/ mervelas / src / projectOnboardingState.ts
Swadhin Biswas feat: implement mervelas cli engine, built-in tools, and reactive UI · 4/3/2026
0358986
84 lines · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import memoize from "lodash-es/memoize.js";
import { join } from "path";
import {
  getCurrentProjectConfig,
  saveCurrentProjectConfig,
} from "./utils/config.js";
import { getCwd } from "./utils/cwd.js";
import { isDirEmpty } from "./utils/file.js";
import { getFsImplementation } from "./utils/fsOperations.js";

export type Step = {
  key: string;
  text: string;
  isComplete: boolean;
  isCompletable: boolean;
  isEnabled: boolean;
};

export function getSteps(): Step[] {
  const hasClaudeMd = getFsImplementation().existsSync(
    join(getCwd(), "MERVELAS.md"),
  );
  const isWorkspaceDirEmpty = isDirEmpty(getCwd());

  return [
    {
      key: "workspace",
      text: "Ask Claude to create a new app or clone a repository",
      isComplete: false,
      isCompletable: true,
      isEnabled: isWorkspaceDirEmpty,
    },
    {
      key: "claudemd",
      text: "Run /init to create a MERVELAS.md file with instructions for Mervelas",
      isComplete: hasClaudeMd,
      isCompletable: true,
      isEnabled: !isWorkspaceDirEmpty,
    },
  ];
}

export function isProjectOnboardingComplete(): boolean {
  return getSteps()
    .filter(({ isCompletable, isEnabled }) => isCompletable && isEnabled)
    .every(({ isComplete }) => isComplete);
}

export function maybeMarkProjectOnboardingComplete(): void {
  // Short-circuit on cached config — isProjectOnboardingComplete() hits
  // the filesystem, and REPL.tsx calls this on every prompt submit.
  if (getCurrentProjectConfig().hasCompletedProjectOnboarding) {
    return;
  }
  if (isProjectOnboardingComplete()) {
    saveCurrentProjectConfig((current) => ({
      ...current,
      hasCompletedProjectOnboarding: true,
    }));
  }
}

export const shouldShowProjectOnboarding = memoize((): boolean => {
  const projectConfig = getCurrentProjectConfig();
  // Short-circuit on cached config before isProjectOnboardingComplete()
  // hits the filesystem — this runs during first render.
  if (
    projectConfig.hasCompletedProjectOnboarding ||
    projectConfig.projectOnboardingSeenCount >= 4 ||
    process.env.IS_DEMO
  ) {
    return false;
  }

  return !isProjectOnboardingComplete();
});

export function incrementProjectOnboardingSeenCount(): void {
  saveCurrentProjectConfig((current) => ({
    ...current,
    projectOnboardingSeenCount: current.projectOnboardingSeenCount + 1,
  }));
}