Skip to content

Commit 8a943eb

Browse files
committed
feat: add doctor and import scripts
1 parent 00efb39 commit 8a943eb

4 files changed

Lines changed: 414 additions & 76 deletions

File tree

β€Žcommands/doctor.mdβ€Ž

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
description: Check whether CodeSensei is installed correctly and show exactly what it stores locally
3+
---
4+
5+
# Doctor
6+
7+
You are CodeSensei πŸ₯‹ by Dojo Coding. The user wants to verify that the plugin is healthy and understand the local storage footprint.
8+
9+
## Instructions
10+
11+
1. Run the doctor script:
12+
13+
```bash
14+
bash ${CLAUDE_PLUGIN_ROOT}/scripts/doctor.sh
15+
```
16+
17+
2. Read the JSON output and summarize it clearly.
18+
19+
3. Display the result in this format:
20+
21+
```
22+
πŸ₯‹ CodeSensei β€” Doctor
23+
━━━━━━━━━━━━━━━━━━━━━━
24+
25+
Status: [βœ… Ready / ⚠️ Needs attention / ❌ Setup required]
26+
27+
Checks
28+
──────
29+
β€’ jq installed: [yes/no]
30+
β€’ Hook config valid: [yes/no]
31+
β€’ Commands detected: [count]
32+
β€’ Profile exists: [yes/no]
33+
β€’ Pending lessons queued: [count]
34+
35+
Profile
36+
───────
37+
β€’ Path: [profile path]
38+
β€’ Belt: [belt]
39+
β€’ XP: [xp]
40+
β€’ Concepts mastered: [count]
41+
β€’ Quizzes taken: [count]
42+
β€’ Current streak: [count]
43+
44+
Stored locally
45+
──────────────
46+
β€’ profile.json
47+
β€’ profile.json.backup
48+
β€’ session-commands.jsonl
49+
β€’ session-changes.jsonl
50+
β€’ sessions.log
51+
β€’ pending-lessons/
52+
β€’ lessons-archive/
53+
β€’ error.log
54+
55+
Issues
56+
──────
57+
[List any reported issues, or β€œNone”]
58+
59+
Next steps
60+
──────────
61+
[List the suggestions from the script, or say β€œYou’re good to go β€” try /code-sensei:explain after your next code change.”]
62+
```
63+
64+
4. Keep the tone calm and operational. This is a diagnostic command, not a marketing moment.

β€Žcommands/import.mdβ€Ž

Lines changed: 49 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -26,121 +26,94 @@ To create an export file first, run:
2626
/code-sensei:export
2727
```
2828

29-
## Step 1: Read and Validate the Import File
29+
## Step 1: Validate and preview using the import script
3030

31-
Read the file at the path the user provided.
31+
Run:
3232

33-
If the file does not exist or cannot be read, show:
33+
```bash
34+
bash ${CLAUDE_PLUGIN_ROOT}/scripts/import-profile.sh [path provided by user]
3435
```
35-
❌ Import failed: File not found at [path]
3636

37-
Check the path and try again.
38-
```
39-
40-
Verify the file is valid JSON in one of these formats:
41-
- Preferred export format: must have a `schema_version` field and a `profile` field containing the profile data
42-
- Legacy/raw export format: may be the raw profile JSON itself, as long as it has at least a `belt` field
37+
Interpret the JSON response:
38+
- `missing_arg` β†’ show the usage block above
39+
- `jq_missing` β†’ tell the user jq is required and how to install it
40+
- `file_not_found` β†’ tell the user the file was not found
41+
- `invalid` β†’ tell the user the export file is not a valid CodeSensei export
42+
- `preview` β†’ continue to Step 2
4343

44-
If validation fails, show:
45-
```
46-
❌ Import failed: Invalid export file
44+
## Step 2: Show the import preview
4745

48-
The file at [path] does not appear to be a valid CodeSensei export.
49-
Expected either a wrapped export (`schema_version` + `profile`) or a raw profile JSON with `belt`.
50-
51-
To create a valid export, run: /code-sensei:export
52-
```
53-
54-
## Step 2: Preview the Import
55-
56-
Show the user what will be imported and ask for confirmation:
46+
For `status = preview`, show:
5747

5848
```
5949
πŸ₯‹ CodeSensei β€” Import Preview
6050
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
6151
6252
Import file: [path]
63-
Exported at: [exported_at from metadata, or "unknown" for legacy/raw exports]
53+
Exported at: [exported_at]
54+
Schema version: [schema_version]
55+
Plugin version: [plugin_version]
6456
6557
Profile to import:
66-
[Belt Emoji] Belt: [belt]
67-
⚑ XP: [xp]
68-
🧠 Concepts mastered: [count of concepts_mastered]
69-
πŸ“Š Quizzes taken: [quizzes.total]
70-
πŸ”₯ Streak: [streak.current] days
58+
[Belt Emoji] Belt: [target_summary.belt]
59+
⚑ XP: [target_summary.xp]
60+
🧠 Concepts mastered: [target_summary.concepts_mastered]
61+
πŸ“Š Quizzes taken: [target_summary.quizzes_total]
62+
πŸ”₯ Streak: [target_summary.streak_current] days
63+
64+
Current profile:
65+
[If current_summary is null: "No existing profile found"]
66+
[Else show the same five lines for current_summary]
7167
7268
⚠️ WARNING: This will overwrite your current profile.
73-
A backup will be saved to ~/.code-sensei/profile.json.backup
69+
A backup will be saved to [backup_path]
7470
7571
Type "yes" to confirm the import, or anything else to cancel.
7672
```
7773

78-
## Step 3: Read Current Profile for Comparison
79-
80-
Before proceeding, read the current profile at `~/.code-sensei/profile.json` (if it exists) and show a brief comparison in the preview if relevant.
74+
## Step 3: Wait for confirmation
8175

82-
## Step 4: Confirm and Apply
76+
If the user does not clearly confirm, show:
8377

84-
Wait for the user's response.
78+
```
79+
↩️ Import cancelled. Your current profile was not changed.
80+
```
8581

86-
**If the user confirms (types "yes" or equivalent affirmation):**
82+
## Step 4: Apply the import
8783

88-
1. Back up the current profile:
89-
- Use the Bash tool to run:
90-
```bash
91-
cp ~/.code-sensei/profile.json ~/.code-sensei/profile.json.backup 2>/dev/null && echo "backed_up" || echo "no_existing_profile"
92-
```
84+
If the user confirms, run:
9385

94-
2. Create the target directory if needed:
95-
- Use the Bash tool to run:
96-
```bash
97-
mkdir -p ~/.code-sensei
98-
```
86+
```bash
87+
bash ${CLAUDE_PLUGIN_ROOT}/scripts/import-profile.sh --apply [path provided by user]
88+
```
9989

100-
3. Extract and write the profile data:
101-
- If the import file has a `profile` field, write `import_data.profile` to `~/.code-sensei/profile.json`
102-
- If it is a legacy/raw export, write the full file contents as-is to `~/.code-sensei/profile.json`
103-
- Use `jq` if available for clean extraction:
104-
```bash
105-
if jq -e '.profile' [import file path] > /dev/null 2>&1; then
106-
jq '.profile' [import file path] > ~/.code-sensei/profile.json
107-
else
108-
cp [import file path] ~/.code-sensei/profile.json
109-
fi
110-
```
111-
- If jq is not available, instruct the user to manually copy the `profile` object from the import file, or the full file for legacy/raw exports
90+
Interpret the response:
91+
- `backup_failed` β†’ say the current profile could not be backed up and nothing changed
92+
- `write_failed` β†’ say the import could not be written
93+
- `imported` β†’ show success
11294

113-
4. Show the success message:
95+
## Step 5: Success format
11496

11597
```
11698
πŸ₯‹ CodeSensei β€” Import Complete
11799
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
118100
119101
βœ… Profile imported successfully!
120102
121-
[Belt Emoji] Belt: [belt]
122-
⚑ XP: [xp]
123-
🧠 Concepts mastered: [count]
124-
πŸ“Š Quizzes taken: [quizzes.total]
103+
[Belt Emoji] Belt: [summary.belt]
104+
⚑ XP: [summary.xp]
105+
🧠 Concepts mastered: [summary.concepts_mastered]
106+
πŸ“Š Quizzes taken: [summary.quizzes_total]
107+
πŸ”₯ Streak: [summary.streak_current] days
125108
126-
Backup saved to: ~/.code-sensei/profile.json.backup
109+
Backup saved to: [backup_path]
127110
128111
Your learning progress has been restored.
129112
Use /code-sensei:progress to view your full dashboard.
130-
131-
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
132-
πŸ₯‹ Powered by Dojo Coding | dojocoding.io
133-
```
134-
135-
**If the user cancels:**
136-
137-
```
138-
↩️ Import cancelled. Your current profile was not changed.
139113
```
140114

141115
## Important Notes
142116

143-
- Always back up before overwriting β€” never skip the backup step
144-
- The preferred import path reads the `profile` field from wrapped exports; legacy/raw exports can be copied directly
145-
- If jq is unavailable, warn the user and provide manual instructions
146-
- After a successful import, do NOT reset session_concepts β€” preserve it as-is from the imported profile
117+
- Always use the import script for validation and apply steps.
118+
- The script supports wrapped exports (`schema_version` + `profile`) and legacy/raw profile JSON exports.
119+
- jq is required for imports. If it is missing, direct the user to `/code-sensei:doctor` after installation to verify setup.

0 commit comments

Comments
Β (0)