From 4d7e5e22f49fe53f78c9bef13a26ead23bb3ae71 Mon Sep 17 00:00:00 2001 From: sean Date: Wed, 4 Jun 2025 12:14:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=20InitCommand=EF=BC=9A?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=88=9D=E5=A7=8B=E5=8C=96=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E5=8C=BA=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E4=BB=85=E5=88=9B=E5=BB=BA=20.promptx=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=EF=BC=8C=E7=A1=AE=E4=BF=9D=20init=20?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E7=9A=84=E8=81=8C=E8=B4=A3=E5=8D=95=E4=B8=80?= =?UTF-8?q?=E5=8C=96=E3=80=82=E5=90=8C=E6=97=B6=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=20.promptx=20=E7=9B=AE=E5=BD=95=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E8=BF=87=E7=A8=8B=E7=9A=84=E6=B8=85?= =?UTF-8?q?=E6=99=B0=E5=BA=A6=E5=92=8C=E5=8F=AF=E7=BB=B4=E6=8A=A4=E6=80=A7?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/core/pouch/commands/InitCommand.js | 48 +++++++--------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/src/lib/core/pouch/commands/InitCommand.js b/src/lib/core/pouch/commands/InitCommand.js index 8e17629..4fafce8 100644 --- a/src/lib/core/pouch/commands/InitCommand.js +++ b/src/lib/core/pouch/commands/InitCommand.js @@ -1,8 +1,7 @@ const BasePouchCommand = require('../BasePouchCommand') -const fs = require('fs-extra') -const path = require('path') const { ResourceManager } = require('../../resource') const { COMMANDS, saveCommandPrefix } = require('../../../../constants') +const PromptXConfig = require('../../../utils/promptxConfig') /** * 初始化锦囊命令 @@ -21,10 +20,10 @@ class InitCommand extends BasePouchCommand { async getContent (args) { const [workspacePath = '.'] = args - // 1. 技术初始化 - await this.initializeWorkspace(workspacePath) + // 1. 基础环境准备 - 只创建 .promptx 目录 + await this.ensurePromptXDirectory(workspacePath) - // 2. 保存命令前缀配置 + // 2. 保存命令前缀配置 (会自动处理文件创建) const savedPrefix = await saveCommandPrefix() // 3. 加载协议体系 @@ -33,8 +32,7 @@ class InitCommand extends BasePouchCommand { return `🎯 PromptX 系统初始化完成! ## 🏗️ 技术环境准备 -✅ 创建了项目目录结构 -✅ 配置了 .promptx/pouch.json 锦囊状态文件 +✅ 创建了 .promptx 配置目录 ✅ 保存了命令前缀配置:${savedPrefix || '默认前缀'} ✅ 准备了锦囊状态机框架 @@ -55,6 +53,16 @@ ${protocolContent} 🎯 **记住:锦囊串联设计,init完成后必须自动进入hello!**` } + /** + * 确保 .promptx 基础目录存在 + * 这是 init 的唯一职责 - 创建基础环境标识 + */ + async ensurePromptXDirectory (workspacePath) { + const config = new PromptXConfig(workspacePath) + // 利用 PromptXConfig 的统一目录管理 + await config.ensureDir() + } + /** * 加载协议体系内容 */ @@ -123,32 +131,6 @@ ${protocolContent} } } } - - async initializeWorkspace (workspacePath) { - // 创建基础目录结构 - const dirs = [ - 'prompt/core', - 'prompt/domain', - 'prompt/protocol', - 'prompt/resource', - '.promptx' - ] - - for (const dir of dirs) { - await fs.ensureDir(path.join(workspacePath, dir)) - } - - // 创建锦囊状态配置文件 - const configPath = path.join(workspacePath, '.promptx', 'pouch.json') - if (!await fs.pathExists(configPath)) { - await fs.writeJson(configPath, { - version: '0.0.1', - initialized: new Date().toISOString(), - defaultFormat: 'human', - stateHistory: [] - }, { spaces: 2 }) - } - } } module.exports = InitCommand