Skip to content

Commit c0f4de8

Browse files
authored
Merge branch 'develop' into hotfix/validate-project-type-err
2 parents 7771f69 + 2c5ba77 commit c0f4de8

File tree

7 files changed

+365
-252
lines changed

7 files changed

+365
-252
lines changed

packages/pwa-kit-mcp/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ The PWA Kit MCP Server offers the following intelligent tools tailored to Salesf
3737
Runs performance and accessibility audits on a provided site URL.
3838
*Example: `https://pwa-kit.mobify-storefront.com`*
3939

40-
* **`git_version_control`**:
41-
Manages the version control of your project using git.
42-
If the project is not already a git repo, project files will be committed as a new local git repo together with a basic .gitignore. If the project is already a git repo, just commit the changes in the project.
43-
4440

4541
## ▶️ Running the MCP Server
4642

packages/pwa-kit-mcp/src/server/server.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import {
1414
CreateNewComponentTool,
1515
DeveloperGuidelinesTool,
1616
TestWithPlaywrightTool,
17-
CreateNewPageTool,
18-
VersionControlGitTool
17+
CreateNewPageTool
1918
} from '../tools'
2019

2120
// NOTE: This is a workaround to import JSON files as ES modules.
@@ -39,18 +38,18 @@ class PwaStorefrontMCPServerHighLevel {
3938
}
4039
)
4140
this.createNewComponentTool = new CreateNewComponentTool()
42-
this.versionControlGitTool = new VersionControlGitTool()
41+
this.createAppGuidelinesTool = new CreateAppGuidelinesTool()
4342
this.testWithPlaywrightTool = new TestWithPlaywrightTool()
4443
this.setupTools()
4544
}
4645

4746
setupTools() {
4847
// Register CreateProjectTool
4948
this.server.tool(
50-
CreateAppGuidelinesTool.name,
51-
CreateAppGuidelinesTool.description,
52-
CreateAppGuidelinesTool.inputSchema,
53-
CreateAppGuidelinesTool.fn
49+
this.createAppGuidelinesTool.name,
50+
this.createAppGuidelinesTool.description,
51+
this.createAppGuidelinesTool.inputSchema,
52+
this.createAppGuidelinesTool.fn
5453
)
5554
this.server.tool(
5655
DeveloperGuidelinesTool.name,
@@ -79,12 +78,6 @@ class PwaStorefrontMCPServerHighLevel {
7978
CreateNewPageTool.inputSchema,
8079
CreateNewPageTool.handler
8180
)
82-
this.server.tool(
83-
this.versionControlGitTool.name,
84-
this.versionControlGitTool.description,
85-
this.versionControlGitTool.inputSchema,
86-
this.versionControlGitTool.handler
87-
)
8881
}
8982

9083
async run() {

packages/pwa-kit-mcp/src/tools/create-app-guideline.js

Lines changed: 108 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
// Project dependencies
99
import {EmptyJsonSchema, getCreateAppCommand, isMonoRepo, runCommand} from '../utils/utils'
10+
import shell from 'shelljs'
11+
import fs from 'fs'
12+
import path from 'path'
1013

1114
const CREATE_APP_COMMAND = getCreateAppCommand()
1215
const DISPLAY_PROGRAM_FLAG = '--displayProgram'
@@ -59,12 +62,15 @@ If the user requests a project using a **template**:
5962
- Presets and templates are mutually exclusive paths. Do not offer both options unless explicitly requested.
6063
- Do not pass any flags to the \`${CREATE_APP_COMMAND}\` CLI tool that are not listed in the program.json options".
6164
- Use the \`${COMMAND_RUNNER}\` command to run the \`${CREATE_APP_COMMAND}\` CLI tool when creating a new project.
62-
- After project creation, prompt the user if **they want to do version control through git** using the **version_control_git** MCP tool.
65+
- After project creation, **MANDATORY**: Always ask the user whether they want to do git version control and commit the files locally.**
66+
- If the user replies "yes" or confirms they want version control:
67+
- Use the integrated version control function and call the \`setupVersionControl\` function to handle git setup
68+
- **IMPORTANT**: You cannot skip asking the user - this interaction is **mandatory** for every project creation.
6369
`
6470

65-
export default {
66-
name: 'create_storefront_app',
67-
description: `
71+
class CreateAppGuidelinesTool {
72+
name = 'create_storefront_app'
73+
description = `
6874
6975
This tool is used to provide the agent with the instructions on how to use the @salesforce/pwa-kit-create-app CLI tool to create a new PWA Kit projects.
7076
@@ -74,9 +80,102 @@ Example Triggers:
7480
- "Create a new PWA Kit app"
7581
- "Start a new storefront using a preset"
7682
- "What templates are available for PWA Kit?"
77-
- "What presets are available for PWA Kit?"`,
78-
inputSchema: EmptyJsonSchema,
79-
fn: async () => {
83+
- "What presets are available for PWA Kit?"`
84+
inputSchema = EmptyJsonSchema
85+
86+
/**
87+
* Handles the version control of your project using git.
88+
* If the directory is not a git repo, it creates a basic .gitignore, runs git init, adds all files, and makes an initial commit.
89+
* If already a git repo, it skips initialization and .gitignore creation, and just adds and commits all files locally.
90+
* @param {string} directory - The directory to initialize the git repository in.
91+
*/
92+
handleGitVersionControl(directory) {
93+
if (!shell.which('git')) {
94+
throw new Error(
95+
'git is not installed or not found in PATH. Please install git to initialize a repository.'
96+
)
97+
}
98+
const isGitRepo = fs.existsSync(path.join(directory, '.git'))
99+
let result
100+
if (isGitRepo) {
101+
// Already a git repo: only add and commit
102+
result = shell.exec('git add .', {cwd: directory, silent: true})
103+
if (result.code !== 0) {
104+
throw new Error(`git add failed: ${result.stderr || result.stdout}`)
105+
}
106+
result = shell.exec('git commit -m "Initial commit"', {cwd: directory, silent: true})
107+
if (result.code !== 0) {
108+
throw new Error(`git commit failed: ${result.stderr || result.stdout}`)
109+
}
110+
} else {
111+
// Not a git repo: create .gitignore, init, add, commit
112+
this.createBasicGitignore(directory)
113+
result = shell.exec('git init', {cwd: directory, silent: true})
114+
if (result.code !== 0) {
115+
throw new Error(`git init failed: ${result.stderr || result.stdout}`)
116+
}
117+
result = shell.exec('git add .', {cwd: directory, silent: true})
118+
if (result.code !== 0) {
119+
throw new Error(`git add failed: ${result.stderr || result.stdout}`)
120+
}
121+
result = shell.exec('git commit -m "Initial commit"', {cwd: directory, silent: true})
122+
if (result.code !== 0) {
123+
throw new Error(`git commit failed: ${result.stderr || result.stdout}`)
124+
}
125+
}
126+
}
127+
128+
/**
129+
* Creates a basic .gitignore file in the given directory.
130+
* @param {string} directory - The directory to create the .gitignore file in.
131+
*/
132+
createBasicGitignore(directory) {
133+
const gitignorePath = path.join(directory, '.gitignore')
134+
if (!fs.existsSync(gitignorePath)) {
135+
fs.writeFileSync(
136+
gitignorePath,
137+
`# Node
138+
node_modules/
139+
.env
140+
.DS_Store
141+
npm-debug.log
142+
yarn-debug.log
143+
yarn-error.log
144+
coverage/
145+
dist/
146+
build/
147+
.next/
148+
out/
149+
logs/
150+
*.log
151+
.idea/
152+
.vscode/
153+
`
154+
)
155+
}
156+
}
157+
158+
/**
159+
* Integrated version control function that can be called after project creation
160+
* @param {string} projectDirectory - The directory where the project was created
161+
* @returns {Object} Result object with success status and message
162+
*/
163+
async setupVersionControl(projectDirectory) {
164+
try {
165+
this.handleGitVersionControl(projectDirectory)
166+
return {
167+
success: true,
168+
message: 'Git version control initialized and committed locally.'
169+
}
170+
} catch (error) {
171+
return {
172+
success: false,
173+
message: `Error: ${error.message}`
174+
}
175+
}
176+
}
177+
178+
fn = async () => {
80179
// Run the display program and get the output.
81180
const programOutput = await runCommand(COMMAND_RUNNER, [
82181
...(COMMAND_RUNNER === 'npx' ? ['--yes'] : []),
@@ -110,3 +209,5 @@ Example Triggers:
110209
}
111210
}
112211
}
212+
213+
export default CreateAppGuidelinesTool

0 commit comments

Comments
 (0)