intention-coding 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +23 -3
- package/dist/index.js +30 -10
- package/dist/utils/common.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4090,6 +4090,27 @@ function removeImagesFromMarkdown(content) {
|
|
|
4090
4090
|
cleaned = cleaned.replace(/\n{3,}/g, '\n\n');
|
|
4091
4091
|
return cleaned.trim();
|
|
4092
4092
|
}
|
|
4093
|
+
async function validateAndResolvePath(filePath) {
|
|
4094
|
+
if ('win32' === process.platform && filePath.startsWith('\\\\')) filePath = '\\\\?\\UNC\\' + filePath.substring(2);
|
|
4095
|
+
const normalized = external_path_default().normalize(filePath);
|
|
4096
|
+
const resolved = external_path_default().resolve(normalized);
|
|
4097
|
+
const cwd = process.cwd();
|
|
4098
|
+
if (!resolved.startsWith(cwd)) {
|
|
4099
|
+
logger_logger.warn(`\u{6587}\u{4EF6}\u{8BBF}\u{95EE}\u{8D85}\u{51FA}\u{5DE5}\u{4F5C}\u{76EE}\u{5F55}: ${filePath}`);
|
|
4100
|
+
throw new Error(`\u{6587}\u{4EF6}\u{8BBF}\u{95EE}\u{8D85}\u{51FA}\u{5DE5}\u{4F5C}\u{76EE}\u{5F55}: ${filePath}`);
|
|
4101
|
+
}
|
|
4102
|
+
if (!resolved.toLowerCase().endsWith('.docx')) {
|
|
4103
|
+
logger_logger.warn(`\u{4EC5}\u{652F}\u{6301}.docx\u{683C}\u{5F0F}\u{6587}\u{4EF6}: ${filePath}`);
|
|
4104
|
+
throw new Error(`\u{4EC5}\u{652F}\u{6301}.docx\u{683C}\u{5F0F}\u{6587}\u{4EF6}: ${filePath}`);
|
|
4105
|
+
}
|
|
4106
|
+
try {
|
|
4107
|
+
await external_fs_namespaceObject.promises.access(resolved, external_fs_namespaceObject.promises.constants.R_OK);
|
|
4108
|
+
} catch (error) {
|
|
4109
|
+
logger_logger.warn(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB}: ${resolved}`, error);
|
|
4110
|
+
throw new Error(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB}: ${resolved}`);
|
|
4111
|
+
}
|
|
4112
|
+
return resolved;
|
|
4113
|
+
}
|
|
4093
4114
|
const promises_namespaceObject = require("fs/promises");
|
|
4094
4115
|
var promises_default = /*#__PURE__*/ __webpack_require__.n(promises_namespaceObject);
|
|
4095
4116
|
const requirementClarifier = {
|
|
@@ -4829,9 +4850,8 @@ const word2mdTool = {
|
|
|
4829
4850
|
const { file_path } = args;
|
|
4830
4851
|
try {
|
|
4831
4852
|
if (!word2md_validateFilePath(file_path)) throw new Error(`\u{6587}\u{4EF6}\u{8DEF}\u{5F84}\u{65E0}\u{6548}: ${file_path}`);
|
|
4832
|
-
const
|
|
4833
|
-
|
|
4834
|
-
const buffer = await promises_namespaceObject.readFile(file_path);
|
|
4853
|
+
const resolvedPath = await validateAndResolvePath(file_path);
|
|
4854
|
+
const buffer = await promises_namespaceObject.readFile(resolvedPath);
|
|
4835
4855
|
const htmlResult = await external_mammoth_namespaceObject.convertToHtml({
|
|
4836
4856
|
buffer
|
|
4837
4857
|
});
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { FastMCP } from "fastmcp";
|
|
3
3
|
import winston from "winston";
|
|
4
4
|
import winston_daily_rotate_file from "winston-daily-rotate-file";
|
|
5
|
-
import fs_0, { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
5
|
+
import fs_0, { existsSync, mkdirSync, promises, readFileSync, writeFileSync } from "fs";
|
|
6
6
|
import path_0, { join } from "path";
|
|
7
|
-
import
|
|
7
|
+
import fs_promises, { mkdir, readFile, writeFile } from "fs/promises";
|
|
8
8
|
import { runCli as external_aico_pack_runCli } from "aico-pack";
|
|
9
9
|
import { convertToHtml } from "mammoth";
|
|
10
10
|
import html_to_md from "html-to-md";
|
|
@@ -4079,6 +4079,27 @@ function removeImagesFromMarkdown(content) {
|
|
|
4079
4079
|
cleaned = cleaned.replace(/\n{3,}/g, '\n\n');
|
|
4080
4080
|
return cleaned.trim();
|
|
4081
4081
|
}
|
|
4082
|
+
async function validateAndResolvePath(filePath) {
|
|
4083
|
+
if ('win32' === process.platform && filePath.startsWith('\\\\')) filePath = '\\\\?\\UNC\\' + filePath.substring(2);
|
|
4084
|
+
const normalized = path_0.normalize(filePath);
|
|
4085
|
+
const resolved = path_0.resolve(normalized);
|
|
4086
|
+
const cwd = process.cwd();
|
|
4087
|
+
if (!resolved.startsWith(cwd)) {
|
|
4088
|
+
logger_logger.warn(`\u{6587}\u{4EF6}\u{8BBF}\u{95EE}\u{8D85}\u{51FA}\u{5DE5}\u{4F5C}\u{76EE}\u{5F55}: ${filePath}`);
|
|
4089
|
+
throw new Error(`\u{6587}\u{4EF6}\u{8BBF}\u{95EE}\u{8D85}\u{51FA}\u{5DE5}\u{4F5C}\u{76EE}\u{5F55}: ${filePath}`);
|
|
4090
|
+
}
|
|
4091
|
+
if (!resolved.toLowerCase().endsWith('.docx')) {
|
|
4092
|
+
logger_logger.warn(`\u{4EC5}\u{652F}\u{6301}.docx\u{683C}\u{5F0F}\u{6587}\u{4EF6}: ${filePath}`);
|
|
4093
|
+
throw new Error(`\u{4EC5}\u{652F}\u{6301}.docx\u{683C}\u{5F0F}\u{6587}\u{4EF6}: ${filePath}`);
|
|
4094
|
+
}
|
|
4095
|
+
try {
|
|
4096
|
+
await promises.access(resolved, promises.constants.R_OK);
|
|
4097
|
+
} catch (error) {
|
|
4098
|
+
logger_logger.warn(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB}: ${resolved}`, error);
|
|
4099
|
+
throw new Error(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB}: ${resolved}`);
|
|
4100
|
+
}
|
|
4101
|
+
return resolved;
|
|
4102
|
+
}
|
|
4082
4103
|
const requirementClarifier = {
|
|
4083
4104
|
name: "requirement_clarifier",
|
|
4084
4105
|
description: "\u9700\u6C42\u5DE5\u7A0B\u5E08 - \u5206\u6790\u7528\u6237\u9700\u6C42\u5B8C\u6574\u6027\uFF0C\u4E3B\u52A8\u53D1\u73B0\u4E0D\u660E\u786E\u7684\u5730\u65B9",
|
|
@@ -4096,7 +4117,7 @@ const requirementClarifier = {
|
|
|
4096
4117
|
});
|
|
4097
4118
|
let context = user_input;
|
|
4098
4119
|
if (file_path) {
|
|
4099
|
-
const markdownContent = await
|
|
4120
|
+
const markdownContent = await fs_promises.readFile(file_path, 'utf8');
|
|
4100
4121
|
context = removeImagesFromMarkdown(markdownContent);
|
|
4101
4122
|
}
|
|
4102
4123
|
const analysisContent = await getAiAnalysis(context);
|
|
@@ -4108,7 +4129,7 @@ const requirementClarifier = {
|
|
|
4108
4129
|
});
|
|
4109
4130
|
const fileName = sanitizeFileName(analysisContent.length > 10 ? analysisContent.substring(0, 10) : `analysis_${Date.now()}`);
|
|
4110
4131
|
const mdDir = path_0.join(getStorageDir(), 'prd');
|
|
4111
|
-
await
|
|
4132
|
+
await fs_promises.mkdir(mdDir, {
|
|
4112
4133
|
recursive: true
|
|
4113
4134
|
});
|
|
4114
4135
|
const mdPath = path_0.join(mdDir, `${fileName}.md`);
|
|
@@ -4128,7 +4149,7 @@ const requirementClarifier = {
|
|
|
4128
4149
|
}))
|
|
4129
4150
|
});
|
|
4130
4151
|
}
|
|
4131
|
-
await
|
|
4152
|
+
await fs_promises.writeFile(mdPath, finalContent, 'utf8');
|
|
4132
4153
|
logger_logger.info({
|
|
4133
4154
|
module: 'requirement_clarifier',
|
|
4134
4155
|
message: "\u9700\u6C42\u5206\u6790\u6587\u4EF6\u5DF2\u4FDD\u5B58",
|
|
@@ -4199,7 +4220,7 @@ const saveSubAnalysisFiles = async (mainDir, contentArray)=>{
|
|
|
4199
4220
|
const safeFileName = `${sanitizeFileName(title)}.md`;
|
|
4200
4221
|
const filePath = path_0.join(mainDir, safeFileName);
|
|
4201
4222
|
try {
|
|
4202
|
-
await
|
|
4223
|
+
await fs_promises.writeFile(filePath, content, 'utf8');
|
|
4203
4224
|
subFiles.push({
|
|
4204
4225
|
title,
|
|
4205
4226
|
path: filePath
|
|
@@ -4471,7 +4492,7 @@ const requirementManagerTool = {
|
|
|
4471
4492
|
};
|
|
4472
4493
|
async function packProject() {
|
|
4473
4494
|
const mdDir = path_0.join(getStorageDir(), 'tech');
|
|
4474
|
-
await
|
|
4495
|
+
await fs_promises.mkdir(mdDir, {
|
|
4475
4496
|
recursive: true
|
|
4476
4497
|
});
|
|
4477
4498
|
logger_logger.info(`\u{1F4C2} \u{6B63}\u{5728}\u{5206}\u{6790}\u{5F53}\u{524D}\u{672C}\u{5730}\u{9879}\u{76EE}`);
|
|
@@ -4812,9 +4833,8 @@ const word2mdTool = {
|
|
|
4812
4833
|
const { file_path } = args;
|
|
4813
4834
|
try {
|
|
4814
4835
|
if (!word2md_validateFilePath(file_path)) throw new Error(`\u{6587}\u{4EF6}\u{8DEF}\u{5F84}\u{65E0}\u{6548}: ${file_path}`);
|
|
4815
|
-
const
|
|
4816
|
-
|
|
4817
|
-
const buffer = await readFile(file_path);
|
|
4836
|
+
const resolvedPath = await validateAndResolvePath(file_path);
|
|
4837
|
+
const buffer = await readFile(resolvedPath);
|
|
4818
4838
|
const htmlResult = await convertToHtml({
|
|
4819
4839
|
buffer
|
|
4820
4840
|
});
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -10,3 +10,7 @@ export declare function removeImagesFromMarkdown(content: string): string;
|
|
|
10
10
|
* 验证文件路径安全性
|
|
11
11
|
*/
|
|
12
12
|
export declare function validateFilePath(filePath: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 安全验证并标准化路径 (新增)
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateAndResolvePath(filePath: string): Promise<string>;
|