新增初始化專案規範工具及相關提示模板,更新思維工具以支持專案規範的生成,並調整相關提示內容以提升用戶體驗。更新 .gitignore 以排除不必要的資料夾。

This commit is contained in:
siage 2025-04-19 03:02:44 +08:00
parent 636377e845
commit f3e376bbde
10 changed files with 222 additions and 8 deletions

2
.gitignore vendored
View File

@ -52,7 +52,7 @@ coverage/
*.sqlite
data/*.json
data/*/*.json
!data/example.json
data/*
# Cursor AI 生成的暫存檔案
.cursor/tmp/

View File

@ -1,8 +1,6 @@
import "dotenv/config";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import { RelatedFileType } from "./types/index.js";
// 導入工具函數
import {
@ -42,6 +40,12 @@ import {
processThoughtSchema,
} from "./tools/thoughtChainTools.js";
// 導入專案工具
import {
initProjectRules,
initProjectRulesSchema,
} from "./tools/projectTools.js";
async function main() {
try {
console.log("啟動蝦米任務管理器服務...");
@ -187,13 +191,23 @@ async function main() {
// 註冊思維鏈工具
server.tool(
"process_thought",
"你可以透過靈活的、可適應和發展的思考過程來分析問題,隨著理解的加深,每個想法都可以建立、質疑或修改先前的見解。你可以質疑想法、假設想法、驗證想法,並且可以建立新的想法。你將重複這個過程,直到你對問題有足夠的理解,並且能夠提出有效的解決方案。如果你覺得思考已經充分可以把 nextThoughtNeeded 設為 false 並且停止思考。",
"任何需要思考或分析的時候,透過該工具進行靈活的、可適應和發展的思考過程來分析問題,隨著理解的加深,每個想法都可以建立、質疑或修改先前的見解。你可以質疑想法、假設想法、驗證想法,並且可以建立新的想法。你將重複這個過程,直到你對問題有足夠的理解,並且能夠提出有效的解決方案。如果你覺得思考已經充分可以把 nextThoughtNeeded 設為 false 並且停止思考,如果你覺得需要更多的思考你可以隨時變更 total_thoughts 來增加步驟。",
processThoughtSchema.shape,
async (args) => {
return await processThought(args);
}
);
// 註冊初始化專案規範工具
server.tool(
"init_project_rules",
"初始化專案規範,當用戶要求產生或初始化專案規範文件時呼叫該工具,如果用戶要求變更或更新專案規範也呼叫該工具",
initProjectRulesSchema.shape,
async () => {
return await initProjectRules();
}
);
// 建立連接
const transport = new StdioServerTransport();
await server.connect(transport);

View File

@ -0,0 +1,32 @@
/**
* initProjectRules prompt
* prompt
*/
import { loadPrompt, generatePrompt } from "../loader.js";
import { initProjectRulesTemplate } from "../templates/initProjectRules.js";
import { getRulesFilePath } from "../../utils/pathUtils.js";
/**
* initProjectRules prompt
*/
export interface InitProjectRulesPromptParams {
// 目前沒有額外參數,未來可按需擴展
}
/**
* initProjectRules prompt
* @param params prompt
* @returns prompt
*/
export function getInitProjectRulesPrompt(
params?: InitProjectRulesPromptParams
): string {
// 使用基本模板
const rulesPath = getRulesFilePath();
const basePrompt = generatePrompt(initProjectRulesTemplate, {
rulesPath,
});
// 載入可能的自定義 prompt (通過環境變數覆蓋或追加)
return loadPrompt(basePrompt, "INIT_PROJECT_RULES");
}

View File

@ -5,7 +5,8 @@
import { loadPrompt, generatePrompt } from "../loader.js";
import * as templates from "../templates/planTask.js";
import { TaskStatus, Task, TaskDependency } from "../../types/index.js";
import { getRulesFilePath } from "../../utils/pathUtils.js";
import { Task, TaskDependency } from "../../types/index.js";
/**
* planTask prompt
@ -178,8 +179,11 @@ export function getPlanTaskPrompt(params: PlanTaskPromptParams): string {
basePrompt += templates.infoCollectionGuideItems2;
basePrompt += templates.infoCollectionGuideItems3;
const rulesPath = getRulesFilePath();
// 添加下一步指導
basePrompt += templates.nextStepsTemplate;
basePrompt += generatePrompt(templates.nextStepsTemplate, {
rulesPath,
});
basePrompt += templates.nextStepsContent1;
basePrompt += templates.nextStepsContent1Detail;

View File

@ -18,4 +18,8 @@ export { getCompleteTaskPrompt } from "./generators/completeTask.js";
export { getListTasksPrompt } from "./generators/listTasks.js";
export { getQueryTaskPrompt } from "./generators/queryTask.js";
export { getGetTaskDetailPrompt } from "./generators/getTaskDetail.js";
export { getInitProjectRulesPrompt } from "./generators/initProjectRules.js";
// 等等
// 導入初始化專案規範模板
export { initProjectRulesTemplate } from "./templates/initProjectRules.js";

View File

@ -0,0 +1,75 @@
/**
* prompt
*
*/
// 基本提示詞模板
export const initProjectRulesTemplate = `請用 「process_thought」 工具思考以下問題
#
##
** AI Agent **
** AI Agent 使(rules.md)**
****
-
- AI
- AI
****
- 使 AI Agent
- README.md /docs/zh/README.md
- 使
-
-
****
-
- LLM
-
##
使
\`\`\`markdown
#
##
###
-
-
\`\`\`
##
1. **** -
2. **** -
3. **** -
4. **** -
5. **//使** - 使
6. **** -
7. **** -
8. **AI ** -
9. **** -
##
1. ** AI ** - prompt Coding Agent AI prompt
2. **** - 使
3. **** -
4. **使** - 使
5. **** - 便 AI
6. **** - 使
7. **** - LLM
rules.md : {rulesPath}
** process_thought Coding Agent **
** rules.md analyze_task**
****
****
`;

View File

@ -87,7 +87,7 @@ export const infoCollectionGuideItems2 = `2. **查詢記憶** - 使用「query_t
export const infoCollectionGuideItems3 = `3. **網路搜索** - 當出現你不理解的名詞或概念時,使用網路搜尋工具找尋答案\n\n`;
// 下一步模板
export const nextStepsTemplate = `## 下一步\n\n`;
export const nextStepsTemplate = `## 下一步\n\n⚠️ 重要:請先閱讀 {rulesPath} 規則再進行任何分析或設計 ⚠️\n\n`;
export const nextStepsContent1 = `**第一步:根據任務描述決定是否查詢記憶**\n`;
export const nextStepsContent1Detail = `- 判斷任務是否屬於必查情境若是請先使用「query_task」查詢過往記錄否則可直接進行分析。\n\n`;
export const nextStepsContent2 = `**第二步:使用 analyze_task 提交分析結果**\n`;

44
src/tools/projectTools.ts Normal file
View File

@ -0,0 +1,44 @@
import { z } from "zod";
import { getInitProjectRulesPrompt } from "../prompts/index.js";
import { getRulesFilePath, ensureRulesFileExists } from "../utils/pathUtils.js";
// 定義schema
export const initProjectRulesSchema = z.object({});
/**
*
*
*/
export async function initProjectRules() {
try {
// 從生成器獲取提示詞
const promptContent = getInitProjectRulesPrompt();
// 確保 DATA_DIR 目錄中存在 rules.md 文件
await ensureRulesFileExists();
// 輸出規則文件的路徑,幫助用戶找到文件
const rulesPath = getRulesFilePath();
// 返回成功響應
return {
content: [
{
type: "text" as const,
text: promptContent + `\n\n規則文件將位於: ${rulesPath}`,
},
],
};
} catch (error) {
// 錯誤處理
const errorMessage = error instanceof Error ? error.message : "未知錯誤";
return {
content: [
{
type: "text" as const,
text: `初始化專案規範時發生錯誤: ${errorMessage}`,
},
],
};
}
}

View File

@ -75,7 +75,7 @@ export const processThoughtSchema = z.object({
.positive({
message: "總思維數必須是正整數",
})
.describe("預計總思維數量"),
.describe("預計總思維數量,如果需要更多的思考可以隨時變更"),
next_thought_needed: z.boolean().describe("是否需要下一步思維"),
stage: z
.string()

41
src/utils/pathUtils.ts Normal file
View File

@ -0,0 +1,41 @@
import fs from "fs/promises";
import path from "path";
import { fileURLToPath } from "url";
// 獲取項目根目錄路徑
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const PROJECT_ROOT = path.resolve(__dirname, "../..");
// 獲取數據目錄路徑
const DATA_DIR = process.env.DATA_DIR || path.join(PROJECT_ROOT, "data");
/**
*
* @returns
*/
export function getRulesFilePath(): string {
return path.join(DATA_DIR, "rules.md");
}
/**
*
*
*/
export async function ensureRulesFileExists(): Promise<void> {
const dataRulesPath = getRulesFilePath();
try {
// 檢查 DATA_DIR 目錄中是否存在規則文件
await fs.access(dataRulesPath);
} catch (error) {
// DATA_DIR 目錄中不存在規則文件
await fs.mkdir(path.dirname(dataRulesPath), { recursive: true });
await fs.writeFile(
dataRulesPath,
"# 開發守則\n\n請在此文件中定義專案規範。",
"utf-8"
);
console.log(`已在 ${dataRulesPath} 創建空規則文件`);
}
}