ai-hero-cli 0.3.0 → 0.4.0

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 (2) hide show
  1. package/bin.cjs +81 -22
  2. package/package.json +1 -1
package/bin.cjs CHANGED
@@ -84759,14 +84759,17 @@ var PromptService = class extends Effect_exports.Service()(
84759
84759
  type: "autocomplete",
84760
84760
  name: "subfolderIndex",
84761
84761
  message: "Select a subfolder",
84762
- choices: subfolders.map((subfolder, index) => ({
84762
+ choices: subfolders.map((subfolder) => ({
84763
84763
  title: subfolder,
84764
- value: index
84764
+ // Use subfolder name as value instead of numeric index
84765
+ // to avoid prompts library treating 0 as falsy and
84766
+ // returning the title string instead (GitHub issue #42)
84767
+ value: subfolder
84765
84768
  }))
84766
84769
  }
84767
84770
  ])
84768
84771
  );
84769
- return subfolderIndex;
84772
+ return subfolders.indexOf(subfolderIndex);
84770
84773
  }
84771
84774
  );
84772
84775
  const selectExerciseAction = Effect_exports.fn(
@@ -84933,6 +84936,7 @@ var parseCommits = (commitHistory) => {
84933
84936
  var selectLessonCommit = ({
84934
84937
  branch,
84935
84938
  excludeCurrentBranch,
84939
+ extraChoices,
84936
84940
  lessonId,
84937
84941
  promptMessage
84938
84942
  }) => Effect_exports.gen(function* () {
@@ -84976,14 +84980,27 @@ var selectLessonCommit = ({
84976
84980
  const sortedCommits = commitsWithLessonIds.sort((a, b) => {
84977
84981
  return a.lessonId.localeCompare(b.lessonId);
84978
84982
  });
84979
- selectedLessonId = yield* promptService.selectLessonCommit(
84980
- sortedCommits.map((commit) => ({
84983
+ const choices = [
84984
+ ...extraChoices ?? [],
84985
+ ...sortedCommits.map((commit) => ({
84981
84986
  lessonId: commit.lessonId,
84982
84987
  message: commit.message
84983
- })),
84988
+ }))
84989
+ ];
84990
+ selectedLessonId = yield* promptService.selectLessonCommit(
84991
+ choices,
84984
84992
  promptMessage
84985
84993
  );
84986
84994
  }
84995
+ const isExtraChoice = extraChoices?.some(
84996
+ (c) => c.lessonId === selectedLessonId
84997
+ );
84998
+ if (isExtraChoice) {
84999
+ return {
85000
+ commit: { sha: "", message: "", lessonId: null },
85001
+ lessonId: selectedLessonId
85002
+ };
85003
+ }
84987
85004
  const matchingCommits = commits.filter(
84988
85005
  (commit) => commit.lessonId === selectedLessonId
84989
85006
  );
@@ -87685,10 +87702,10 @@ var internal = Command_exports.make("internal").pipe(
87685
87702
  );
87686
87703
 
87687
87704
  // src/pull.ts
87688
- var InvalidBranchOperationError2 = class extends Data_exports.TaggedError(
87705
+ (class extends Data_exports.TaggedError(
87689
87706
  "InvalidBranchOperationError"
87690
87707
  ) {
87691
- };
87708
+ });
87692
87709
  var UncommittedChangesError = class extends Data_exports.TaggedError(
87693
87710
  "UncommittedChangesError"
87694
87711
  ) {
@@ -87696,11 +87713,17 @@ var UncommittedChangesError = class extends Data_exports.TaggedError(
87696
87713
  var runPull = (opts) => Effect_exports.gen(function* () {
87697
87714
  const git = yield* GitService;
87698
87715
  yield* git.ensureIsGitRepo();
87699
- const currentBranch = yield* git.getCurrentBranch();
87700
- if (currentBranch === "main") {
87701
- return yield* new InvalidBranchOperationError2({
87702
- message: "Cannot pull when on main branch. Switch to a working branch first."
87703
- });
87716
+ let workingBranch = yield* git.getCurrentBranch();
87717
+ if (workingBranch === "main") {
87718
+ const promptService = yield* PromptService;
87719
+ yield* Console_exports.log(
87720
+ "You're on the main branch. To avoid losing work, create a dev branch to pull upstream changes into."
87721
+ );
87722
+ const branchName = yield* promptService.inputBranchName(
87723
+ "working"
87724
+ );
87725
+ yield* git.checkoutNewBranch(branchName);
87726
+ workingBranch = branchName;
87704
87727
  }
87705
87728
  const { hasUncommittedChanges, statusOutput } = yield* git.getUncommittedChanges();
87706
87729
  if (hasUncommittedChanges) {
@@ -87712,12 +87735,12 @@ var runPull = (opts) => Effect_exports.gen(function* () {
87712
87735
  yield* Console_exports.log("Fetching main from upstream...");
87713
87736
  yield* git.fetch("upstream", "main");
87714
87737
  yield* Console_exports.log(
87715
- `Merging upstream/main into ${currentBranch}...`
87738
+ `Merging upstream/main into ${workingBranch}...`
87716
87739
  );
87717
87740
  yield* git.merge("upstream/main");
87718
87741
  yield* Console_exports.log(
87719
87742
  `
87720
- \u2713 Successfully merged upstream/main into ${currentBranch}`
87743
+ \u2713 Successfully merged upstream/main into ${workingBranch}`
87721
87744
  );
87722
87745
  });
87723
87746
  var pull = Command_exports.make(
@@ -87774,6 +87797,17 @@ var pull = Command_exports.make(
87774
87797
  );
87775
87798
  process.exitCode = 1;
87776
87799
  });
87800
+ },
87801
+ PromptCancelledError: () => {
87802
+ return Effect_exports.gen(function* () {
87803
+ yield* Console_exports.log("\nPull cancelled.");
87804
+ });
87805
+ },
87806
+ FailedToCreateBranchError: (error4) => {
87807
+ return Effect_exports.gen(function* () {
87808
+ yield* Console_exports.error(`Error: ${error4.message}`);
87809
+ process.exitCode = 1;
87810
+ });
87777
87811
  }
87778
87812
  }),
87779
87813
  Effect_exports.catchAll((error4) => {
@@ -87808,14 +87842,39 @@ var runReset = ({
87808
87842
  yield* git.ensureUpstreamBranchConnected({
87809
87843
  targetBranch: branch
87810
87844
  });
87811
- const { commit: targetCommit, lessonId: selectedLessonId } = yield* selectLessonCommit({
87812
- branch,
87813
- lessonId,
87814
- promptMessage: "Which lesson do you want to reset to? (type to search)",
87815
- excludeCurrentBranch: false
87816
- });
87817
- const commitToUse = targetCommit.sha;
87845
+ const isExplicitMain = Option_exports.isSome(lessonId) && lessonId.value === "main";
87846
+ let commitToUse;
87847
+ let selectedLessonId;
87848
+ if (isExplicitMain) {
87849
+ yield* git.fetch("upstream", "main");
87850
+ commitToUse = yield* git.revParse("upstream/main");
87851
+ selectedLessonId = "main";
87852
+ } else {
87853
+ const result = yield* selectLessonCommit({
87854
+ branch,
87855
+ lessonId,
87856
+ promptMessage: "Which lesson do you want to reset to? (type to search)",
87857
+ excludeCurrentBranch: false,
87858
+ extraChoices: [
87859
+ { lessonId: "main", message: "Reset to the starting point" }
87860
+ ]
87861
+ });
87862
+ if (result.lessonId === "main") {
87863
+ yield* git.fetch("upstream", "main");
87864
+ commitToUse = yield* git.revParse("upstream/main");
87865
+ selectedLessonId = "main";
87866
+ } else {
87867
+ commitToUse = result.commit.sha;
87868
+ selectedLessonId = result.lessonId;
87869
+ }
87870
+ }
87871
+ const isResetToMain = selectedLessonId === "main";
87818
87872
  const currentBranch = yield* git.getCurrentBranch();
87873
+ if (isResetToMain && currentBranch === "main") {
87874
+ return yield* new InvalidBranchOperationError3({
87875
+ message: "Cannot reset to main while on the main branch. Create a new branch first."
87876
+ });
87877
+ }
87819
87878
  let action;
87820
87879
  if (currentBranch === "main") {
87821
87880
  yield* Console_exports.log(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-hero-cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "The CLI used to run exercises for the AI Hero course",
6
6
  "bin": "bin.cjs",