pyb-ts
Version:
PYB-CLI - Minimal AI Agent with multi-model support and CLI interface
100 lines (99 loc) • 5.58 kB
JavaScript
import * as React from "react";
import { OrderedList } from "@inkjs/ui";
import { Box, Text } from "ink";
import {
getCurrentProjectConfig,
getGlobalConfig,
saveCurrentProjectConfig,
saveGlobalConfig
} from "@utils/config";
import { existsSync } from "fs";
import { join } from "path";
import { homedir } from "os";
import terminalSetup from "@commands/terminalSetup";
import { getTheme } from "@utils/theme";
import { RELEASE_NOTES } from "@constants/releaseNotes";
import { gt } from "semver";
import { isDirEmpty } from "@utils/file";
import { MACRO } from "@constants/macros";
import { PROJECT_FILE, PRODUCT_NAME } from "@constants/product";
function markProjectOnboardingComplete() {
const projectConfig = getCurrentProjectConfig();
if (!projectConfig.hasCompletedProjectOnboarding) {
saveCurrentProjectConfig({
...projectConfig,
hasCompletedProjectOnboarding: true
});
}
}
function markReleaseNotesSeen() {
const config = getGlobalConfig();
saveGlobalConfig({
...config,
lastReleaseNotesSeen: MACRO.VERSION
});
}
function ProjectOnboarding({
workspaceDir
}) {
const projectConfig = getCurrentProjectConfig();
const showOnboarding = !projectConfig.hasCompletedProjectOnboarding;
const config = getGlobalConfig();
const previousVersion = config.lastReleaseNotesSeen;
let releaseNotesToShow = [];
if (!previousVersion || gt(MACRO.VERSION, previousVersion)) {
releaseNotesToShow = RELEASE_NOTES[MACRO.VERSION] || [];
}
const hasReleaseNotes = releaseNotesToShow.length > 0;
React.useEffect(() => {
if (hasReleaseNotes && !showOnboarding) {
markReleaseNotesSeen();
}
}, [hasReleaseNotes, showOnboarding]);
if (!showOnboarding && !hasReleaseNotes) {
return null;
}
const workspaceHasProjectGuide = existsSync(join(workspaceDir, PROJECT_FILE));
const isWorkspaceDirEmpty = isDirEmpty(workspaceDir);
const shouldRecommendProjectGuide = !workspaceHasProjectGuide && !isWorkspaceDirEmpty;
const showTerminalTip = terminalSetup.isEnabled && !getGlobalConfig().shiftEnterKeyBindingInstalled;
const theme = getTheme();
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", gap: 1, padding: 1, paddingBottom: 0 }, showOnboarding && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, "Tips for getting started:"), /* @__PURE__ */ React.createElement(OrderedList, null, (() => {
const items = [];
if (isWorkspaceDirEmpty) {
items.push(
/* @__PURE__ */ React.createElement(React.Fragment, { key: "workspace" }, /* @__PURE__ */ React.createElement(OrderedList.Item, null, /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, "Ask ", PRODUCT_NAME, " to create a new app or clone a repository.")))
);
}
if (shouldRecommendProjectGuide) {
items.push(
/* @__PURE__ */ React.createElement(React.Fragment, { key: "projectGuide" }, /* @__PURE__ */ React.createElement(OrderedList.Item, null, /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, "Run ", /* @__PURE__ */ React.createElement(Text, { color: theme.text }, "/init"), " to create a\xA0", PROJECT_FILE, " file with instructions for ", PRODUCT_NAME, ".")))
);
}
if (showTerminalTip) {
items.push(
/* @__PURE__ */ React.createElement(React.Fragment, { key: "terminal" }, /* @__PURE__ */ React.createElement(OrderedList.Item, null, /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, "Run ", /* @__PURE__ */ React.createElement(Text, { color: theme.text }, "/terminal-setup"), /* @__PURE__ */ React.createElement(Text, { bold: false }, " to set up terminal integration"))))
);
}
items.push(
/* @__PURE__ */ React.createElement(React.Fragment, { key: "questions" }, /* @__PURE__ */ React.createElement(OrderedList.Item, null, /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, "Ask ", PRODUCT_NAME, " questions about your codebase.")))
);
items.push(
/* @__PURE__ */ React.createElement(React.Fragment, { key: "changes" }, /* @__PURE__ */ React.createElement(OrderedList.Item, null, /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, "Ask ", PRODUCT_NAME, " to implement changes to your codebase.")))
);
return items;
})())), !showOnboarding && hasReleaseNotes && /* @__PURE__ */ React.createElement(
Box,
{
borderColor: getTheme().secondaryBorder,
flexDirection: "column",
marginRight: 1
},
/* @__PURE__ */ React.createElement(Box, { flexDirection: "column", gap: 0 }, /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, null, "\u{1F195} What's new in v", MACRO.VERSION, ":")), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginLeft: 1 }, releaseNotesToShow.map((note, noteIndex) => /* @__PURE__ */ React.createElement(React.Fragment, { key: noteIndex }, /* @__PURE__ */ React.createElement(Text, { color: getTheme().secondaryText }, "\uFFFD\uFFFD?", note)))))
), workspaceDir === homedir() && /* @__PURE__ */ React.createElement(Text, { color: getTheme().warning }, "Note: You have launched ", /* @__PURE__ */ React.createElement(Text, { bold: true }, "anon-code"), " in your home directory. For the best experience, launch it in a project directory instead."));
}
export {
ProjectOnboarding as default,
markProjectOnboardingComplete
};
//# sourceMappingURL=ProjectOnboarding.js.map