移除無用程式

This commit is contained in:
siage 2025-05-05 16:32:19 +08:00
parent 04f55cb2e3
commit ea40e782b3
5 changed files with 0 additions and 430 deletions

View File

@ -1,43 +0,0 @@
// 任務狀態枚舉:定義任務在工作流程中的當前階段
export var TaskStatus;
(function (TaskStatus) {
TaskStatus["PENDING"] = "\u5F85\u8655\u7406";
TaskStatus["IN_PROGRESS"] = "\u9032\u884C\u4E2D";
TaskStatus["COMPLETED"] = "\u5DF2\u5B8C\u6210";
TaskStatus["BLOCKED"] = "\u88AB\u963B\u64CB";
})(TaskStatus || (TaskStatus = {}));
// 相關文件類型:定義文件與任務的關係類型
export var RelatedFileType;
(function (RelatedFileType) {
RelatedFileType["TO_MODIFY"] = "\u5F85\u4FEE\u6539";
RelatedFileType["REFERENCE"] = "\u53C3\u8003\u8CC7\u6599";
RelatedFileType["OUTPUT"] = "\u8F38\u51FA\u7D50\u679C";
RelatedFileType["DEPENDENCY"] = "\u4F9D\u8CF4\u6587\u4EF6";
RelatedFileType["OTHER"] = "\u5176\u4ED6";
})(RelatedFileType || (RelatedFileType = {}));
// 任務複雜度級別:定義任務的複雜程度分類
export var TaskComplexityLevel;
(function (TaskComplexityLevel) {
TaskComplexityLevel["LOW"] = "\u4F4E\u8907\u96DC\u5EA6";
TaskComplexityLevel["MEDIUM"] = "\u4E2D\u7B49\u8907\u96DC\u5EA6";
TaskComplexityLevel["HIGH"] = "\u9AD8\u8907\u96DC\u5EA6";
TaskComplexityLevel["VERY_HIGH"] = "\u6975\u9AD8\u8907\u96DC\u5EA6";
})(TaskComplexityLevel || (TaskComplexityLevel = {}));
// 任務複雜度閾值:定義任務複雜度評估的參考標準
export const TaskComplexityThresholds = {
DESCRIPTION_LENGTH: {
MEDIUM: 500, // 超過此字數判定為中等複雜度
HIGH: 1000, // 超過此字數判定為高複雜度
VERY_HIGH: 2000, // 超過此字數判定為極高複雜度
},
DEPENDENCIES_COUNT: {
MEDIUM: 2, // 超過此依賴數量判定為中等複雜度
HIGH: 5, // 超過此依賴數量判定為高複雜度
VERY_HIGH: 10, // 超過此依賴數量判定為極高複雜度
},
NOTES_LENGTH: {
MEDIUM: 200, // 超過此字數判定為中等複雜度
HIGH: 500, // 超過此字數判定為高複雜度
VERY_HIGH: 1000, // 超過此字數判定為極高複雜度
},
};

View File

@ -92,6 +92,3 @@ export interface TaskComplexityAssessment {
}; };
recommendations: string[]; // 處理建議列表 recommendations: string[]; // 處理建議列表
} }
// 思維鏈資料結構
export * from "./thoughtChain.js";

View File

@ -1,34 +0,0 @@
/**
*
*
*
*
*/
/**
*
*/
export enum ThoughtStage {
PROBLEM_DEFINITION = "問題定義", // 定義問題和目標的階段
COLLECT_INFORMATION = "收集資訊", // 收集和分析資訊的階段
RESEARCH = "研究", // 研究資訊的階段
ANALYSIS = "分析", // 深入解析問題和可能解決方案的階段
SYNTHESIS = "綜合", // 整合分析結果形成方案的階段
CONCLUSION = "結論", // 總結思考過程並提出最終解決方案的階段
QUESTIONING = "質疑", // 質疑和批判的階段
PLANNING = "規劃", // 規劃和計劃的階段
}
/**
*
*/
export interface ThoughtData {
thought: string; // 思維內容(字串)
thoughtNumber: number; // 當前思維編號(數字)
totalThoughts: number; // 預估總思維數量(數字)
nextThoughtNeeded: boolean; // 是否需要更多思維(布林值)
stage: string; // 思維階段(字串,如「問題定義」、「研究」、「分析」、「綜合」、「結論」、「質疑」)
tags?: string[]; // 可選的思維關鍵詞或分類(字串陣列)
axioms_used?: string[]; // 可選的此思維中使用的原則或公理(字串陣列)
assumptions_challenged?: string[]; // 可選的此思維挑戰的假設(字串陣列)
}

View File

@ -1,84 +0,0 @@
import { RelatedFileType } from "../types/index.js";
/**
* 生成任務相關文件的內容摘要
*
* 此函數根據提供的 RelatedFile 物件列表生成文件的摘要信息而不實際讀取檔案內容
* 這是一個輕量級的實現僅基於檔案元數據如路徑類型描述等生成格式化的摘要
* 適用於需要提供文件上下文信息但不需要訪問實際檔案內容的情境
*
* @param relatedFiles 相關文件列表 - RelatedFile 物件數組包含文件的路徑類型描述等資訊
* @param maxTotalLength 摘要內容的最大總長度 - 控制生成摘要的總字符數避免過大的返回內容
* @returns 格式化的文件摘要資訊
*/
export async function loadTaskRelatedFiles(
relatedFiles,
maxTotalLength = 15000 // 控制生成內容的總長度
) {
if (!relatedFiles || relatedFiles.length === 0) {
return "## 相關文件\n\n無相關文件";
}
let filesSummary = `## 相關文件內容摘要 (共 ${relatedFiles.length} 個文件)\n\n`;
let totalLength = 0;
// 按文件類型優先級排序(首先處理待修改的文件)
const priorityOrder = {
[RelatedFileType.TO_MODIFY]: 1,
[RelatedFileType.REFERENCE]: 2,
[RelatedFileType.DEPENDENCY]: 3,
[RelatedFileType.OUTPUT]: 4,
[RelatedFileType.OTHER]: 5,
};
const sortedFiles = [...relatedFiles].sort(
(a, b) => priorityOrder[a.type] - priorityOrder[b.type]
);
// 處理每個文件
for (const file of sortedFiles) {
if (totalLength >= maxTotalLength) {
filesSummary += `\n### 已達到上下文長度限制,部分文件未載入\n`;
break;
}
// 生成文件基本資訊
const fileInfo = generateFileInfo(file);
// 添加到總內容
const fileHeader = `\n### ${file.type}: ${file.path}${
file.description ? ` - ${file.description}` : ""
}${
file.lineStart && file.lineEnd
? ` (行 ${file.lineStart}-${file.lineEnd})`
: ""
}\n\n`;
filesSummary += fileHeader + "```\n" + fileInfo + "\n```\n\n";
totalLength += fileInfo.length + fileHeader.length + 8; // 8 for "```\n" and "\n```"
}
return filesSummary;
}
/**
* 生成文件基本資訊摘要
*
* 根據檔案的元數據生成格式化的資訊摘要包含檔案路徑類型和相關提示
* 不讀取實際檔案內容僅基於提供的 RelatedFile 物件生成信息
*
* @param file 相關文件物件 - 包含檔案路徑類型描述等基本資訊
* @returns 格式化的檔案資訊摘要文字
*/
function generateFileInfo(file) {
let fileInfo = `檔案: ${file.path}\n`;
fileInfo += `類型: ${file.type}\n`;
if (file.description) {
fileInfo += `描述: ${file.description}\n`;
}
if (file.lineStart && file.lineEnd) {
fileInfo += `行範圍: ${file.lineStart}-${file.lineEnd}\n`;
}
fileInfo += `若需查看實際內容,請直接查看檔案: ${file.path}\n`;
return fileInfo;
}

View File

@ -1,266 +0,0 @@
/**
*
*
* 使
* 1.
* 2.
* 3.
*/
// 定義關鍵詞與其權重
const KEYWORDS = {
// 任務相關
任務: 1.5,
功能: 1.3,
實現: 1.3,
開發: 1.3,
完成: 1.2,
執行: 1.2,
驗證: 1.2,
錯誤: 1.5,
問題: 1.5,
修復: 1.5,
失敗: 1.8,
成功: 1.5,
依賴: 1.2,
阻擋: 1.4,
風險: 1.4,
優化: 1.3,
改進: 1.3,
// 決策相關
決定: 1.6,
選擇: 1.5,
決策: 1.6,
方案: 1.5,
架構: 1.5,
設計: 1.4,
結構: 1.4,
// 技術相關
代碼: 1.3,
測試: 1.3,
函數: 1.2,
接口: 1.2,
類型: 1.2,
模塊: 1.2,
組件: 1.2,
數據: 1.3,
文件: 1.2,
路徑: 1.1,
// 系統狀態
狀態: 1.3,
啟動: 1.3,
停止: 1.3,
創建: 1.3,
刪除: 1.4,
更新: 1.3,
查詢: 1.2,
// 負面信息(需要重點關注)
警告: 1.8,
異常: 1.8,
崩潰: 2.0,
嚴重: 1.8,
危險: 1.8,
緊急: 1.9,
};
/**
*
* @param text
* @param maxLength
* @returns
*/
export function extractSummary(text: string, maxLength: number = 100): string {
if (!text) return "";
// 移除 Markdown 格式
const plainText = text
.replace(/```[\s\S]*?```/g, "") // 移除代碼塊
.replace(/#+\s/g, "") // 移除標題標記
.replace(/\*\*/g, "") // 移除粗體標記
.replace(/\*/g, "") // 移除斜體標記
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") // 將連結替換為文本
.replace(/\n/g, " ") // 將換行符替換為空格
.replace(/\s+/g, " ") // 將多個空格替換為單個空格
.trim();
// 如果文本長度在允許範圍內,直接返回
if (plainText.length <= maxLength) {
return plainText;
}
// 取前段並添加省略號
return plainText.substring(0, maxLength - 3) + "...";
}
/**
*
* @param taskName
* @param taskDescription
* @param completionDetails
* @returns
*/
export function generateTaskSummary(
taskName: string,
taskDescription: string,
completionDetails?: string
): string {
// 如果提供了完成細節,優先使用
if (completionDetails) {
return extractSummary(completionDetails, 250);
}
// 否則從任務名稱和描述生成摘要
const baseText = `${taskName}已成功完成。該任務涉及${extractSummary(
taskDescription,
200
)}`;
return extractSummary(baseText, 250);
}
/**
*
*
* @param text
* @returns
*/
function splitIntoSentences(text: string): string[] {
// 使用正則表達式分割句子
// 匹配中文和英文的句號、問號、驚嘆號,以及換行符
const sentenceSplitters = /(?<=[。.!?\n])\s*/g;
const sentences = text
.split(sentenceSplitters)
.filter((s) => s.trim().length > 0);
return sentences;
}
/**
*
*
* @param sentence
* @param index
* @param totalSentences
* @returns
*/
function scoreSentence(
sentence: string,
index: number,
totalSentences: number
): number {
let score = 1.0;
// 位置因素:文檔開頭和結尾的句子通常更重要
if (index === 0 || index === totalSentences - 1) {
score *= 1.5;
} else if (
index < Math.ceil(totalSentences * 0.2) ||
index >= Math.floor(totalSentences * 0.8)
) {
score *= 1.25;
}
// 句子長度因素:過短的句子可能信息量較少,過長的句子可能包含太多信息
const wordCount = sentence.split(/\s+/).length;
if (wordCount < 3) {
score *= 0.8;
} else if (wordCount > 25) {
score *= 0.9;
} else if (wordCount >= 5 && wordCount <= 15) {
score *= 1.2;
}
// 關鍵詞因素:包含關鍵詞的句子更重要
for (const [keyword, weight] of Object.entries(KEYWORDS)) {
if (sentence.includes(keyword)) {
score *= weight;
}
}
// 句子結構因素:特殊句式可能更重要
if (
sentence.includes("總結") ||
sentence.includes("結論") ||
sentence.includes("因此") ||
sentence.includes("所以")
) {
score *= 1.5;
}
// 數字和專有名詞因素:包含數字和專有名詞的句子通常更重要
if (/\d+/.test(sentence)) {
score *= 1.3;
}
return score;
}
/**
*
*
* @param content
* @param maxLength
* @returns
*/
export function extractTitle(content: string, maxLength: number = 50): string {
// 防禦性檢查
if (!content || content.trim().length === 0) {
return "";
}
// 分割為句子
const sentences = splitIntoSentences(content);
if (sentences.length === 0) {
return "";
}
// 先考慮第一個句子
let title = sentences[0];
// 如果第一個句子太長,找到第一個逗號或其他分隔符截斷
if (title.length > maxLength) {
const firstPart = title.split(/[,:]/)[0];
if (firstPart && firstPart.length < maxLength) {
title = firstPart;
} else {
title = title.substring(0, maxLength - 3) + "...";
}
}
return title;
}
/**
*
*
* @param messages
* @param maxLength
* @returns
*/
export function extractSummaryFromConversation(
messages: Array<{ role: string; content: string }>,
maxLength: number = 200
): string {
// 防禦性檢查
if (!messages || messages.length === 0) {
return "";
}
// 如果只有一條消息,直接提取其摘要
if (messages.length === 1) {
return extractSummary(messages[0].content, maxLength);
}
// 連接所有消息,但保留角色信息
const combinedText = messages
.map((msg) => `${msg.role}: ${msg.content}`)
.join("\n");
// 從組合文本提取摘要
const summary = extractSummary(combinedText, maxLength);
return summary;
}