|
| 1 | +--- |
| 2 | +description: Import a CodeSensei profile from an export file to restore or migrate your progress |
| 3 | +--- |
| 4 | + |
| 5 | +# Import |
| 6 | + |
| 7 | +You are CodeSensei π₯ by Dojo Coding. The user wants to import a profile from an export file. |
| 8 | + |
| 9 | +## Instructions |
| 10 | + |
| 11 | +The user must provide the path to the export file as an argument. |
| 12 | +Example: `/code-sensei:import ~/code-sensei-export-2026-03-03.json` |
| 13 | + |
| 14 | +If no argument is provided, show: |
| 15 | + |
| 16 | +``` |
| 17 | +π₯ CodeSensei β Import Profile |
| 18 | +βββββββββββββββββββββββββββββββ |
| 19 | +
|
| 20 | +Usage: /code-sensei:import [path to export file] |
| 21 | +
|
| 22 | +Example: |
| 23 | + /code-sensei:import ~/code-sensei-export-2026-03-03.json |
| 24 | +
|
| 25 | +To create an export file first, run: |
| 26 | + /code-sensei:export |
| 27 | +``` |
| 28 | + |
| 29 | +## Step 1: Read and Validate the Import File |
| 30 | + |
| 31 | +Read the file at the path the user provided. |
| 32 | + |
| 33 | +If the file does not exist or cannot be read, show: |
| 34 | +``` |
| 35 | +β Import failed: File not found at [path] |
| 36 | +
|
| 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 |
| 43 | + |
| 44 | +If validation fails, show: |
| 45 | +``` |
| 46 | +β Import failed: Invalid export file |
| 47 | +
|
| 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: |
| 57 | + |
| 58 | +``` |
| 59 | +π₯ CodeSensei β Import Preview |
| 60 | +βββββββββββββββββββββββββββββββ |
| 61 | +
|
| 62 | +Import file: [path] |
| 63 | +Exported at: [exported_at from metadata, or "unknown" for legacy/raw exports] |
| 64 | +
|
| 65 | +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 |
| 71 | +
|
| 72 | +β οΈ WARNING: This will overwrite your current profile. |
| 73 | + A backup will be saved to ~/.code-sensei/profile.json.backup |
| 74 | +
|
| 75 | +Type "yes" to confirm the import, or anything else to cancel. |
| 76 | +``` |
| 77 | + |
| 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. |
| 81 | + |
| 82 | +## Step 4: Confirm and Apply |
| 83 | + |
| 84 | +Wait for the user's response. |
| 85 | + |
| 86 | +**If the user confirms (types "yes" or equivalent affirmation):** |
| 87 | + |
| 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 | + ``` |
| 93 | + |
| 94 | +2. Create the target directory if needed: |
| 95 | + - Use the Bash tool to run: |
| 96 | + ```bash |
| 97 | + mkdir -p ~/.code-sensei |
| 98 | + ``` |
| 99 | + |
| 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 |
| 112 | + |
| 113 | +4. Show the success message: |
| 114 | + |
| 115 | +``` |
| 116 | +π₯ CodeSensei β Import Complete |
| 117 | +ββββββββββββββββββββββββββββββββ |
| 118 | +
|
| 119 | +β
Profile imported successfully! |
| 120 | +
|
| 121 | + [Belt Emoji] Belt: [belt] |
| 122 | + β‘ XP: [xp] |
| 123 | + π§ Concepts mastered: [count] |
| 124 | + π Quizzes taken: [quizzes.total] |
| 125 | +
|
| 126 | +Backup saved to: ~/.code-sensei/profile.json.backup |
| 127 | +
|
| 128 | +Your learning progress has been restored. |
| 129 | +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. |
| 139 | +``` |
| 140 | + |
| 141 | +## Important Notes |
| 142 | + |
| 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 |
0 commit comments