learn_bash_from_session_data 1.0.6 → 1.0.8
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/README.md +141 -18
- package/bin/learn-bash.js +17 -14
- package/package.json +1 -1
- package/scripts/html_generator.py +183 -14
- package/scripts/quiz_generator.py +114 -40
- package/bash-learner-output/run-2026-02-05-154214/index.html +0 -3848
- package/bash-learner-output/run-2026-02-05-154214/summary.json +0 -148
- package/bash-learner-output/run-2026-02-05-155427/index.html +0 -3900
- package/bash-learner-output/run-2026-02-05-155427/summary.json +0 -157
- package/bash-learner-output/run-2026-02-05-155949/index.html +0 -4514
- package/bash-learner-output/run-2026-02-05-155949/summary.json +0 -163
- package/vectors.db +0 -0
|
@@ -729,20 +729,44 @@ def _generate_distractor_flags(cmd: str, correct_flag: str, count: int = 3) -> l
|
|
|
729
729
|
|
|
730
730
|
|
|
731
731
|
def _generate_distractor_descriptions(correct_desc: str, count: int = 3) -> list[str]:
|
|
732
|
-
"""Generate plausible wrong descriptions."""
|
|
732
|
+
"""Generate plausible wrong descriptions using command-level descriptions for length parity."""
|
|
733
733
|
distractors = []
|
|
734
734
|
|
|
735
|
-
#
|
|
736
|
-
|
|
737
|
-
for
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
735
|
+
# First: collect command-level descriptions from COMMAND_DB (similar length to correct answer)
|
|
736
|
+
cmd_descriptions = []
|
|
737
|
+
for cmd_name in COMMAND_DB:
|
|
738
|
+
cmd_info = COMMAND_DB[cmd_name]
|
|
739
|
+
desc = cmd_info.get('description', '')
|
|
740
|
+
if desc and desc.lower() != correct_desc.lower():
|
|
741
|
+
# Truncate very long descriptions to similar length as correct answer
|
|
742
|
+
max_len = max(len(correct_desc) + 40, 80)
|
|
743
|
+
if len(desc) > max_len:
|
|
744
|
+
desc = desc[:max_len].rsplit(' ', 1)[0] + '...'
|
|
745
|
+
cmd_descriptions.append(desc)
|
|
746
|
+
|
|
747
|
+
if cmd_descriptions:
|
|
748
|
+
random.shuffle(cmd_descriptions)
|
|
749
|
+
distractors.extend(cmd_descriptions[:count])
|
|
750
|
+
|
|
751
|
+
# Fallback: use flag descriptions if not enough command descriptions
|
|
752
|
+
if len(distractors) < count:
|
|
753
|
+
all_flag_descs = []
|
|
754
|
+
for cmd in _get_all_flagged_commands():
|
|
755
|
+
all_flag_descs.extend(_get_flags_for_cmd(cmd).values())
|
|
756
|
+
all_flag_descs = list(set(all_flag_descs))
|
|
757
|
+
all_flag_descs = [d for d in all_flag_descs if d.lower() != correct_desc.lower()]
|
|
758
|
+
random.shuffle(all_flag_descs)
|
|
759
|
+
distractors.extend(all_flag_descs[:count - len(distractors)])
|
|
760
|
+
|
|
761
|
+
# Remove duplicates
|
|
762
|
+
seen = set()
|
|
763
|
+
unique = []
|
|
764
|
+
for d in distractors:
|
|
765
|
+
dl = d.lower()
|
|
766
|
+
if dl not in seen:
|
|
767
|
+
seen.add(dl)
|
|
768
|
+
unique.append(d)
|
|
769
|
+
return unique[:count]
|
|
746
770
|
|
|
747
771
|
|
|
748
772
|
def generate_what_does_quiz(
|
|
@@ -793,9 +817,27 @@ def generate_what_does_quiz(
|
|
|
793
817
|
for rel_cmd in related_cmds[:3 - len(distractor_descriptions)]:
|
|
794
818
|
distractor_descriptions.append(f"Runs {rel_cmd} to process files")
|
|
795
819
|
|
|
796
|
-
# Ensure we have exactly 3 distractors
|
|
820
|
+
# Ensure we have exactly 3 distractors with plausible alternatives
|
|
821
|
+
fallback_actions = [
|
|
822
|
+
f"List directory contents with detailed file information",
|
|
823
|
+
f"Search recursively through files for matching patterns",
|
|
824
|
+
f"Display or modify file permissions and ownership",
|
|
825
|
+
f"Compress or archive files for storage and transfer",
|
|
826
|
+
f"Monitor system processes and resource usage",
|
|
827
|
+
f"Download files from a remote server or URL",
|
|
828
|
+
f"Edit configuration files in the default text editor",
|
|
829
|
+
f"Install or update packages from the package manager",
|
|
830
|
+
]
|
|
831
|
+
random.shuffle(fallback_actions)
|
|
832
|
+
fb_idx = 0
|
|
797
833
|
while len(distractor_descriptions) < 3:
|
|
798
|
-
|
|
834
|
+
if fb_idx < len(fallback_actions):
|
|
835
|
+
fallback = fallback_actions[fb_idx]
|
|
836
|
+
if fallback.lower() != correct_desc.lower():
|
|
837
|
+
distractor_descriptions.append(fallback)
|
|
838
|
+
fb_idx += 1
|
|
839
|
+
else:
|
|
840
|
+
distractor_descriptions.append(f"Run a system utility to process input data")
|
|
799
841
|
|
|
800
842
|
# Create options (shuffle positions)
|
|
801
843
|
options = []
|
|
@@ -929,19 +971,20 @@ def generate_build_command_quiz(
|
|
|
929
971
|
parsed = _parse_command(cmd_string)
|
|
930
972
|
base_cmd = parsed["base"]
|
|
931
973
|
|
|
932
|
-
#
|
|
933
|
-
|
|
934
|
-
correct_answer = " ".join(correct_components)
|
|
974
|
+
# Use the original command string as correct answer (preserves flag-argument ordering)
|
|
975
|
+
correct_answer = cmd_string.strip()
|
|
935
976
|
|
|
936
|
-
# Generate wrong arrangements
|
|
977
|
+
# Generate wrong arrangements using parsed components
|
|
978
|
+
all_parts = [base_cmd] + parsed["flags"] + parsed["args"]
|
|
937
979
|
distractors = []
|
|
938
980
|
|
|
939
|
-
# Distractor 1: Wrong order
|
|
940
|
-
if len(
|
|
941
|
-
wrong_order =
|
|
981
|
+
# Distractor 1: Wrong order of components
|
|
982
|
+
if len(all_parts) > 2:
|
|
983
|
+
wrong_order = all_parts.copy()
|
|
942
984
|
random.shuffle(wrong_order)
|
|
943
|
-
|
|
944
|
-
|
|
985
|
+
wrong_str = " ".join(wrong_order)
|
|
986
|
+
if wrong_str != correct_answer:
|
|
987
|
+
distractors.append(wrong_str)
|
|
945
988
|
|
|
946
989
|
# Distractor 2: Missing flag
|
|
947
990
|
if parsed["flags"]:
|
|
@@ -961,15 +1004,31 @@ def generate_build_command_quiz(
|
|
|
961
1004
|
wrong_cmd = [related[0]] + parsed["flags"] + parsed["args"]
|
|
962
1005
|
distractors.append(" ".join(wrong_cmd))
|
|
963
1006
|
|
|
964
|
-
# Ensure we have exactly 3 distractors
|
|
1007
|
+
# Ensure we have exactly 3 distractors with plausible alternatives
|
|
1008
|
+
# Use real flags from the knowledge base as fallback distractors
|
|
1009
|
+
all_cmd_flags = list(_get_flags_for_cmd(base_cmd).keys())
|
|
1010
|
+
random.shuffle(all_cmd_flags)
|
|
1011
|
+
fb_flag_idx = 0
|
|
965
1012
|
while len(distractors) < 3:
|
|
966
|
-
|
|
967
|
-
|
|
1013
|
+
if fb_flag_idx < len(all_cmd_flags):
|
|
1014
|
+
fallback_flag = all_cmd_flags[fb_flag_idx]
|
|
1015
|
+
fallback_cmd = f"{base_cmd} {fallback_flag} {' '.join(parsed['args'])}"
|
|
1016
|
+
if fallback_cmd.strip() != correct_answer:
|
|
1017
|
+
distractors.append(fallback_cmd.strip())
|
|
1018
|
+
fb_flag_idx += 1
|
|
1019
|
+
else:
|
|
1020
|
+
# Use a related command as last resort
|
|
1021
|
+
related = _get_related_commands(base_cmd)
|
|
1022
|
+
if related:
|
|
1023
|
+
rel = related[len(distractors) % len(related)]
|
|
1024
|
+
distractors.append(f"{rel} {' '.join(parsed['flags'])} {' '.join(parsed['args'])}".strip())
|
|
1025
|
+
else:
|
|
1026
|
+
distractors.append(f"{base_cmd} {' '.join(parsed['args'])}".strip())
|
|
968
1027
|
|
|
969
1028
|
# Remove duplicates and correct answer from distractors
|
|
970
1029
|
distractors = list(set(d for d in distractors if d != correct_answer))[:3]
|
|
971
1030
|
while len(distractors) < 3:
|
|
972
|
-
distractors.append(f"{base_cmd}
|
|
1031
|
+
distractors.append(f"{base_cmd} {' '.join(parsed['args'])}".strip())
|
|
973
1032
|
|
|
974
1033
|
# Create options
|
|
975
1034
|
all_answers = [correct_answer] + distractors[:3]
|
|
@@ -1203,7 +1262,13 @@ def generate_quiz_set(
|
|
|
1203
1262
|
target_build = max(1, int(count * 0.2))
|
|
1204
1263
|
target_spot_diff = max(1, int(count * 0.15))
|
|
1205
1264
|
|
|
1206
|
-
|
|
1265
|
+
# Track used commands per quiz type to avoid repeating the same command
|
|
1266
|
+
used_per_type = {
|
|
1267
|
+
QuizType.WHAT_DOES: set(),
|
|
1268
|
+
QuizType.WHICH_FLAG: set(),
|
|
1269
|
+
QuizType.BUILD_COMMAND: set(),
|
|
1270
|
+
QuizType.SPOT_DIFFERENCE: set(),
|
|
1271
|
+
}
|
|
1207
1272
|
|
|
1208
1273
|
# Generate "What does this do?" questions
|
|
1209
1274
|
random.shuffle(weighted_commands)
|
|
@@ -1211,38 +1276,47 @@ def generate_quiz_set(
|
|
|
1211
1276
|
if len([q for q in questions if q.quiz_type == QuizType.WHAT_DOES]) >= target_what_does:
|
|
1212
1277
|
break
|
|
1213
1278
|
cmd_id = cmd.get("command", "")
|
|
1214
|
-
if cmd_id not in
|
|
1279
|
+
if cmd_id not in used_per_type[QuizType.WHAT_DOES]:
|
|
1215
1280
|
q = generate_what_does_quiz(cmd)
|
|
1216
1281
|
questions.append(q)
|
|
1217
|
-
|
|
1282
|
+
used_per_type[QuizType.WHAT_DOES].add(cmd_id)
|
|
1218
1283
|
|
|
1219
1284
|
# Generate "Which flag?" questions
|
|
1220
1285
|
random.shuffle(weighted_commands)
|
|
1221
1286
|
for cmd in weighted_commands:
|
|
1222
1287
|
if len([q for q in questions if q.quiz_type == QuizType.WHICH_FLAG]) >= target_which_flag:
|
|
1223
1288
|
break
|
|
1224
|
-
|
|
1225
|
-
if
|
|
1226
|
-
|
|
1289
|
+
cmd_id = cmd.get("command", "")
|
|
1290
|
+
if cmd_id not in used_per_type[QuizType.WHICH_FLAG]:
|
|
1291
|
+
q = generate_which_flag_quiz(cmd)
|
|
1292
|
+
if q:
|
|
1293
|
+
questions.append(q)
|
|
1294
|
+
used_per_type[QuizType.WHICH_FLAG].add(cmd_id)
|
|
1227
1295
|
|
|
1228
1296
|
# Generate "Build the command" questions
|
|
1229
1297
|
random.shuffle(weighted_commands)
|
|
1230
1298
|
for cmd in weighted_commands:
|
|
1231
1299
|
if len([q for q in questions if q.quiz_type == QuizType.BUILD_COMMAND]) >= target_build:
|
|
1232
1300
|
break
|
|
1233
|
-
|
|
1234
|
-
|
|
1301
|
+
cmd_id = cmd.get("command", "")
|
|
1302
|
+
if cmd_id not in used_per_type[QuizType.BUILD_COMMAND]:
|
|
1303
|
+
q = generate_build_command_quiz(cmd)
|
|
1304
|
+
questions.append(q)
|
|
1305
|
+
used_per_type[QuizType.BUILD_COMMAND].add(cmd_id)
|
|
1235
1306
|
|
|
1236
1307
|
# Generate "Spot the difference" questions
|
|
1237
1308
|
random.shuffle(weighted_commands)
|
|
1238
1309
|
for cmd in weighted_commands:
|
|
1239
1310
|
if len([q for q in questions if q.quiz_type == QuizType.SPOT_DIFFERENCE]) >= target_spot_diff:
|
|
1240
1311
|
break
|
|
1241
|
-
|
|
1242
|
-
if
|
|
1243
|
-
|
|
1244
|
-
if
|
|
1245
|
-
|
|
1312
|
+
cmd_id = cmd.get("command", "")
|
|
1313
|
+
if cmd_id not in used_per_type[QuizType.SPOT_DIFFERENCE]:
|
|
1314
|
+
variant = _create_similar_command_variant(cmd)
|
|
1315
|
+
if variant:
|
|
1316
|
+
q = generate_spot_difference_quiz(cmd, variant)
|
|
1317
|
+
if q:
|
|
1318
|
+
questions.append(q)
|
|
1319
|
+
used_per_type[QuizType.SPOT_DIFFERENCE].add(cmd_id)
|
|
1246
1320
|
|
|
1247
1321
|
# Shuffle final questions
|
|
1248
1322
|
random.shuffle(questions)
|