@@ -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
6252Import 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
6557Profile 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
7571Type "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
128111Your learning progress has been restored.
129112Use /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