更新toolDefinitions.js中的描述,增加了使用工具时的环境验证提示,以提升用户在使用专业角色选择和变身器时的安全性和准确性。同时,在DirectoryLocator.js中引入AI驱动的项目管理器,优化了项目路径查找策略,确保更高的查找优先级和灵活性。

This commit is contained in:
sean
2025-06-16 15:12:15 +08:00
parent 3d29434d24
commit 048053f18c
2 changed files with 59 additions and 14 deletions

View File

@ -27,7 +27,7 @@ const TOOL_DEFINITIONS = [
}, },
{ {
name: 'promptx_hello', name: 'promptx_hello',
description: '🎭 [专业角色选择菜单] 🔥 当你需要专业能力时必须先看这个 - 展示大量可激活的专家身份清单:产品经理/Java开发者/UI设计师/文案策划师/数据分析师/项目经理等,每个角色都有完整的专业思维模式和工作技能,看完后选择最适合当前任务的专家身份', description: '🎭 [专业角色选择菜单] 🔥 当你需要专业能力时必须先看这个 - 展示大量可激活的专家身份清单:产品经理/Java开发者/UI设计师/文案策划师/数据分析师/项目经理等,每个角色都有完整的专业思维模式和工作技能。🛑 **重要**:使用此工具时必须首先关注并响应工具返回结果开头的项目环境验证提示,确认项目路径正确后再处理角色列表内容,看完后选择最适合当前任务的专家身份',
inputSchema: { inputSchema: {
type: 'object', type: 'object',
properties: {} properties: {}
@ -36,7 +36,7 @@ const TOOL_DEFINITIONS = [
}, },
{ {
name: 'promptx_action', name: 'promptx_action',
description: '⚡ [专家身份变身器] 🚀 让你瞬间获得指定专业角色的完整思维和技能包 - 输入角色ID立即获得该领域专家的思考方式/工作原则/专业知识同时自动加载相关历史经验和最佳实践3秒内完成专业化转换每次需要专业服务时必须使用', description: '⚡ [专家身份变身器] 🚀 让你瞬间获得指定专业角色的完整思维和技能包 - 输入角色ID立即获得该领域专家的思考方式/工作原则/专业知识同时自动加载相关历史经验和最佳实践3秒内完成专业化转换。🛑 **重要**:使用此工具时必须首先关注并响应工具返回结果开头的项目环境验证提示,确认项目路径正确后再处理角色激活内容,每次需要专业服务时必须使用',
inputSchema: { inputSchema: {
type: 'object', type: 'object',
properties: { properties: {
@ -53,7 +53,7 @@ const TOOL_DEFINITIONS = [
}, },
{ {
name: 'promptx_learn', name: 'promptx_learn',
description: '🧠 [专业技能学习器] 💎 让你快速掌握特定专业技能和思维方式 - 学习创意思维/最佳实践/敏捷开发/产品设计等专业能力支持thought://(思维模式) execution://(执行技能) knowledge://(专业知识)三种学习类型,学会后立即可以运用到工作中,想要专业化成长时使用', description: '🧠 [专业技能学习器] 💎 让你快速掌握特定专业技能和思维方式 - 学习创意思维/最佳实践/敏捷开发/产品设计等专业能力支持thought://(思维模式) execution://(执行技能) knowledge://(专业知识)三种学习类型。🛑 **重要**:使用此工具时必须首先关注并响应工具返回结果开头的项目环境验证提示,确认项目路径正确后再处理学习内容,学会后立即可以运用到工作中,想要专业化成长时使用',
inputSchema: { inputSchema: {
type: 'object', type: 'object',
properties: { properties: {

View File

@ -1,6 +1,7 @@
const fs = require('fs-extra') const fs = require('fs-extra')
const path = require('path') const path = require('path')
const os = require('os') const os = require('os')
const CurrentProjectManager = require('./CurrentProjectManager')
/** /**
* 目录定位器基础抽象类 * 目录定位器基础抽象类
@ -90,13 +91,17 @@ class ProjectRootLocator extends DirectoryLocator {
constructor(options = {}) { constructor(options = {}) {
super(options) super(options)
// 初始化AI驱动的项目管理器
this.currentProjectManager = new CurrentProjectManager()
// 可配置的查找策略优先级(按可靠性和准确性排序) // 可配置的查找策略优先级(按可靠性和准确性排序)
this.strategies = options.strategies || [ this.strategies = options.strategies || [
'existingPromptxDirectory', // 1. 现有.promptx目录最可靠的项目标识 'aiProvidedProjectPath', // 1. AI提供的项目路径最可靠由AI告知
'packageJsonDirectory', // 2. 向上查找项目标识文件(最准确的项目边界 'existingPromptxDirectory', // 2. 现有.promptx目录最可靠的项目标识
'gitRootDirectory', // 3. Git根目录通用可靠 'packageJsonDirectory', // 3. 向上查找项目标识文件(最准确的项目边界
'currentWorkingDirectoryIfHasMarkers', // 4. 当前目录项目标识(降级策略 'gitRootDirectory', // 4. Git根目录通用可靠
'currentWorkingDirectory' // 5. 当前目录(最后回退 'currentWorkingDirectoryIfHasMarkers', // 5. 当前目录项目标识(降级策略
'currentWorkingDirectory' // 6. 纯当前目录(最后回退)
] ]
// 项目标识文件 // 项目标识文件
@ -144,6 +149,9 @@ class ProjectRootLocator extends DirectoryLocator {
*/ */
async _executeStrategy(strategy, startDir, context) { async _executeStrategy(strategy, startDir, context) {
switch (strategy) { switch (strategy) {
case 'aiProvidedProjectPath':
return await this._findByAIProvidedPath()
case 'existingPromptxDirectory': case 'existingPromptxDirectory':
return await this._findByExistingPromptx(startDir) return await this._findByExistingPromptx(startDir)
@ -164,6 +172,21 @@ class ProjectRootLocator extends DirectoryLocator {
} }
} }
/**
* 通过AI提供的项目路径查找最高优先级
*/
async _findByAIProvidedPath() {
try {
const aiProvidedPath = await this.currentProjectManager.getCurrentProject()
if (aiProvidedPath && await this.isValidDirectory(aiProvidedPath)) {
return aiProvidedPath
}
} catch (error) {
// AI提供的路径获取失败继续使用其他策略
}
return null
}
/** /**
* 检查当前目录是否包含项目标识文件 * 检查当前目录是否包含项目标识文件
*/ */
@ -270,6 +293,7 @@ class PromptXWorkspaceLocator extends DirectoryLocator {
constructor(options = {}) { constructor(options = {}) {
super(options) super(options)
this.projectRootLocator = options.projectRootLocator || new ProjectRootLocator(options) this.projectRootLocator = options.projectRootLocator || new ProjectRootLocator(options)
this.currentProjectManager = new CurrentProjectManager()
} }
/** /**
@ -284,19 +308,25 @@ class PromptXWorkspaceLocator extends DirectoryLocator {
return cached return cached
} }
// 策略1IDE环境变量最高优先级 - 用户/IDE明确指定 // 策略1AI提供的项目路径最高优先级 - AI驱动的路径管理
const workspaceFromAI = await this._fromAIProvidedPath()
if (workspaceFromAI) {
return this.setCached(cacheKey, workspaceFromAI)
}
// 策略2IDE环境变量用户/IDE明确指定
const workspaceFromIDE = await this._fromIDEEnvironment() const workspaceFromIDE = await this._fromIDEEnvironment()
if (workspaceFromIDE) { if (workspaceFromIDE) {
return this.setCached(cacheKey, workspaceFromIDE) return this.setCached(cacheKey, workspaceFromIDE)
} }
// 策略2PromptX专用环境变量用户手动配置 // 策略3PromptX专用环境变量用户手动配置
const workspaceFromEnv = await this._fromPromptXEnvironment() const workspaceFromEnv = await this._fromPromptXEnvironment()
if (workspaceFromEnv) { if (workspaceFromEnv) {
return this.setCached(cacheKey, workspaceFromEnv) return this.setCached(cacheKey, workspaceFromEnv)
} }
// 策略3特定上下文策略如init命令的强制指定 // 策略4特定上下文策略如init命令的强制指定
if (context.strategies) { if (context.strategies) {
const workspaceFromProject = await this._fromProjectRoot(context) const workspaceFromProject = await this._fromProjectRoot(context)
if (workspaceFromProject) { if (workspaceFromProject) {
@ -304,22 +334,37 @@ class PromptXWorkspaceLocator extends DirectoryLocator {
} }
} }
// 策略4:现有.promptx目录已初始化的项目 // 策略5:现有.promptx目录已初始化的项目
const workspaceFromExisting = await this._fromExistingDirectory(context.startDir) const workspaceFromExisting = await this._fromExistingDirectory(context.startDir)
if (workspaceFromExisting) { if (workspaceFromExisting) {
return this.setCached(cacheKey, workspaceFromExisting) return this.setCached(cacheKey, workspaceFromExisting)
} }
// 策略5:项目根目录(基于项目结构推断) // 策略6:项目根目录(基于项目结构推断)
const workspaceFromProject = await this._fromProjectRoot(context) const workspaceFromProject = await this._fromProjectRoot(context)
if (workspaceFromProject) { if (workspaceFromProject) {
return this.setCached(cacheKey, workspaceFromProject) return this.setCached(cacheKey, workspaceFromProject)
} }
// 策略6:智能回退策略(兜底方案) // 策略7:智能回退策略(兜底方案)
return this.setCached(cacheKey, await this._getSmartFallback(context)) return this.setCached(cacheKey, await this._getSmartFallback(context))
} }
/**
* 从AI提供的项目路径获取最高优先级
*/
async _fromAIProvidedPath() {
try {
const aiProvidedPath = await this.currentProjectManager.getCurrentProject()
if (aiProvidedPath && await this.isValidDirectory(aiProvidedPath)) {
return aiProvidedPath
}
} catch (error) {
// AI提供的路径获取失败继续使用其他策略
}
return null
}
/** /**
* 从IDE环境变量获取支持多种IDE * 从IDE环境变量获取支持多种IDE
*/ */