-
Notifications
You must be signed in to change notification settings - Fork 4
feat(init): configure Sanity MCP and install agent skill in one combined step #1124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7381af4
c2fbcd9
42f1857
8b934a5
ec5d6cc
3bea22c
61275bf
59f54c7
951b4e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sanity/cli': minor | ||
| --- | ||
|
|
||
| Configure Sanity MCP and install the `sanity-best-practices` agent skill for detected AI editors in a single step during `sanity init`. Add `--no-skills` to opt out. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import {vi, type Mock} from 'vitest' | ||
| import {type Mock, vi} from 'vitest' | ||
|
|
||
| /** | ||
| * @internal | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,9 @@ import {getProjectDefaults} from '../../util/getProjectDefaults.js' | |
| import {validateSession} from '../auth/ensureAuthenticated.js' | ||
| import {getProviderName} from '../auth/getProviderName.js' | ||
| import {login} from '../auth/login/login.js' | ||
| import {detectAvailableEditors} from '../mcp/detectAvailableEditors.js' | ||
| import {setupMCP} from '../mcp/setupMCP.js' | ||
| import {setupSkills} from '../skills/setupSkills.js' | ||
| import {checkNextJsReactCompatibility} from './checkNextJsReactCompatibility.js' | ||
| import {determineAppTemplate} from './determineAppTemplate.js' | ||
| import {createOrAppendEnvVars} from './env/createOrAppendEnvVars.js' | ||
|
|
@@ -187,7 +189,18 @@ export async function initAction(options: InitOptions, context: InitContext): Pr | |
| workDir, | ||
| }) | ||
|
|
||
| const mcpResult = await setupMCP({mode: options.mcpMode}) | ||
| // Detect editors once, then share the result with MCP and skills setup so | ||
| // we don't pay the detection cost (filesystem probes + CLI execa calls) twice. | ||
| const detectedEditors = | ||
| options.mcpMode === 'skip' && options.skillsMode === 'skip' | ||
| ? [] | ||
| : await detectAvailableEditors() | ||
|
|
||
| const mcpResult = await setupMCP({ | ||
| editors: detectedEditors, | ||
| mode: options.mcpMode, | ||
| skillsMode: options.skillsMode, | ||
| }) | ||
|
|
||
| trace.log({ | ||
| configuredEditors: mcpResult.configuredEditors, | ||
|
|
@@ -200,6 +213,26 @@ export async function initAction(options: InitOptions, context: InitContext): Pr | |
| } | ||
| const mcpConfigured = mcpResult.configuredEditors | ||
|
|
||
| async function installSkills(): Promise<void> { | ||
| if (mcpResult.skillsToInstall.length === 0) return | ||
| try { | ||
| const skillsResult = await setupSkills({agents: mcpResult.skillsToInstall}) | ||
| trace.log({ | ||
| installedAgents: skillsResult.installedAgents, | ||
| skipped: skillsResult.skipped, | ||
| step: 'skillsSetup', | ||
| }) | ||
| if (skillsResult.error) { | ||
| trace.error(skillsResult.error) | ||
| } | ||
| } catch (error) { | ||
| const err = error instanceof Error ? error : new Error(String(error)) | ||
| debug('Unexpected error from setupSkills %O', err) | ||
| output.warn(`Could not install Sanity agent skills: ${err.message}`) | ||
| trace.error(err) | ||
| } | ||
| } | ||
|
|
||
| const {alreadyConfiguredEditors} = mcpResult | ||
| if (alreadyConfiguredEditors.length > 0) { | ||
| const label = | ||
|
|
@@ -229,6 +262,7 @@ export async function initAction(options: InitOptions, context: InitContext): Pr | |
| trace, | ||
| workDir, | ||
| }) | ||
| await installSkills() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing
|
||
| trace.complete() | ||
| return | ||
| } | ||
|
|
@@ -273,6 +307,8 @@ export async function initAction(options: InitOptions, context: InitContext): Pr | |
| projectId, | ||
| })) | ||
|
|
||
| await installSkills() | ||
|
|
||
| trace.complete() | ||
| } | ||
|
|
||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.