intention-coding 0.5.1 → 0.5.2

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 CHANGED
@@ -318,18 +318,39 @@ var __webpack_exports__ = {};
318
318
  var external_html_to_md_default = /*#__PURE__*/ __webpack_require__.n(external_html_to_md_namespaceObject);
319
319
  const external_os_namespaceObject = require("os");
320
320
  const sanitizeFileName = (input)=>input.replace(/[\\/:*?"<>|\n\r#%&]/g, '').trim().replace(/\s+/g, '_').replace(/_+/g, '_').replace(/^_+|_+$/g, '');
321
- async function validateAndResolvePath(filePath) {
322
- if ('win32' === process.platform && filePath.startsWith('\\\\')) filePath = '\\\\?\\UNC\\' + filePath.substring(2);
321
+ function normalizePath(filePath) {
322
+ if (!filePath || 'string' != typeof filePath) throw new Error("\u6587\u4EF6\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A");
323
+ filePath = filePath.trim().replace(/^["']|["']$/g, '');
324
+ if ('win32' === process.platform) {
325
+ if (filePath.startsWith('\\\\')) return '\\\\?\\UNC\\' + filePath.substring(2);
326
+ if (filePath.match(/^[a-zA-Z]:/)) filePath = filePath.replace(/\\/g, '/');
327
+ }
323
328
  const normalized = external_path_default().normalize(filePath);
324
329
  const resolved = external_path_default().resolve(normalized);
330
+ return resolved;
331
+ }
332
+ async function validateAndResolvePath(filePath) {
333
+ if (!filePath) throw new Error("\u6587\u4EF6\u8DEF\u5F84\u53C2\u6570\u7F3A\u5931\uFF0C\u8BF7\u63D0\u4F9B filePath \u53C2\u6570");
334
+ const resolved = normalizePath(filePath);
325
335
  try {
326
336
  await external_fs_namespaceObject.promises.access(resolved, external_fs_namespaceObject.constants.R_OK);
327
337
  } catch (error) {
328
- logger.warn(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB}: ${resolved}`, error);
329
- throw new Error(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB}: ${resolved}`);
338
+ const osInfo = `[${process.platform}]`;
339
+ logger.warn(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB} ${osInfo}: ${resolved}`, error);
340
+ throw new Error(`\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}\u{6216}\u{4E0D}\u{53EF}\u{8BFB} ${osInfo}: ${resolved}`);
330
341
  }
331
342
  return resolved;
332
343
  }
344
+ function isValidExcelPath(filePath) {
345
+ if (!filePath) return false;
346
+ const normalized = normalizePath(filePath);
347
+ const ext = external_path_default().extname(normalized).toLowerCase();
348
+ return [
349
+ '.xlsx',
350
+ '.xls',
351
+ '.xlsm'
352
+ ].includes(ext);
353
+ }
333
354
  var util_util;
334
355
  (function(util) {
335
356
  util.assertEqual = (_)=>{};
@@ -6660,12 +6681,15 @@ ${allTextContent || "\u672A\u8BC6\u522B\u5230\u6587\u5B57\u5185\u5BB9"}
6660
6681
  const { filePath, options = {} } = args;
6661
6682
  if (!filePath) throw new Error("\u6587\u4EF6\u8DEF\u5F84\u53C2\u6570\u7F3A\u5931\uFF0C\u8BF7\u63D0\u4F9B filePath \u53C2\u6570");
6662
6683
  try {
6684
+ if (!isValidExcelPath(filePath)) throw new Error(`\u{6587}\u{4EF6}\u{683C}\u{5F0F}\u{4E0D}\u{652F}\u{6301}\u{FF0C}\u{8BF7}\u{63D0}\u{4F9B}\u{6709}\u{6548}\u{7684}Excel\u{6587}\u{4EF6}\u{8DEF}\u{5F84}(.xlsx, .xls, .xlsm): ${filePath}`);
6663
6685
  const resolvedPath = await validateAndResolvePath(filePath);
6664
- try {
6665
- await promises_namespaceObject.access(resolvedPath);
6666
- } catch {
6667
- throw new Error(`Excel\u{6587}\u{4EF6}\u{4E0D}\u{5B58}\u{5728}: ${resolvedPath}`);
6668
- }
6686
+ logger.info("\u5F00\u59CB\u8BFB\u53D6Excel\u6587\u4EF6", {
6687
+ tool: 'read_excel',
6688
+ originalPath: filePath,
6689
+ resolvedPath: resolvedPath,
6690
+ platform: process.platform,
6691
+ options: options
6692
+ });
6669
6693
  const buffer = await promises_namespaceObject.readFile(resolvedPath);
6670
6694
  const workbook = external_xlsx_namespaceObject.read(buffer, {
6671
6695
  type: 'buffer',
@@ -6737,20 +6761,29 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
6737
6761
  };
6738
6762
  } catch (error) {
6739
6763
  const errorMsg = error instanceof Error ? error.message : String(error);
6740
- logger.error(`Excel\u{8BFB}\u{53D6}\u{5931}\u{8D25}: ${errorMsg}`, {
6764
+ const osInfo = `[${process.platform}]`;
6765
+ logger.error(`Excel\u{8BFB}\u{53D6}\u{5931}\u{8D25} ${osInfo}: ${errorMsg}`, {
6741
6766
  tool: "read_excel",
6742
6767
  filePath,
6768
+ resolvedPath: error.resolvedPath || filePath,
6769
+ platform: process.platform,
6743
6770
  options
6744
6771
  });
6772
+ let userFriendlyMessage = `Excel\u{8BFB}\u{53D6}\u{5931}\u{8D25}: ${errorMsg}`;
6773
+ if (errorMsg.includes("\u6587\u4EF6\u4E0D\u5B58\u5728")) userFriendlyMessage += "\n\uD83D\uDCA1 \u89E3\u51B3\u65B9\u6848\uFF1A\u8BF7\u68C0\u67E5\u6587\u4EF6\u8DEF\u5F84\u662F\u5426\u6B63\u786E\uFF0C\u786E\u4FDD\u6587\u4EF6\u5B58\u5728\u4E14\u53EF\u8BFB";
6774
+ else if (errorMsg.includes("\u6587\u4EF6\u683C\u5F0F\u4E0D\u652F\u6301")) userFriendlyMessage += "\n\uD83D\uDCA1 \u89E3\u51B3\u65B9\u6848\uFF1A\u8BF7\u786E\u4FDD\u6587\u4EF6\u662F\u6709\u6548\u7684Excel\u683C\u5F0F(.xlsx, .xls, .xlsm)";
6775
+ else if (errorMsg.includes("\u8DEF\u5F84\u53C2\u6570\u7F3A\u5931")) userFriendlyMessage += "\n\uD83D\uDCA1 \u89E3\u51B3\u65B9\u6848\uFF1A\u8BF7\u63D0\u4F9B\u5B8C\u6574\u7684\u6587\u4EF6\u8DEF\u5F84\u53C2\u6570";
6745
6776
  return {
6746
6777
  content: [
6747
6778
  {
6748
6779
  type: "text",
6749
6780
  text: JSON.stringify({
6750
6781
  success: false,
6751
- message: `Excel\u{8BFB}\u{53D6}\u{5931}\u{8D25}: ${errorMsg}`,
6782
+ message: userFriendlyMessage,
6783
+ platform: process.platform,
6784
+ originalPath: filePath,
6752
6785
  data: null
6753
- })
6786
+ }, null, 2)
6754
6787
  }
6755
6788
  ],
6756
6789
  isError: true
@@ -6857,7 +6890,7 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
6857
6890
  };
6858
6891
  external_xlsx_namespaceObject.utils.book_append_sheet(workbook, worksheet, options.sheetName || 'Sheet1');
6859
6892
  let finalOutputPath;
6860
- if (outputPath) finalOutputPath = await validateAndResolvePath(outputPath);
6893
+ if (outputPath) finalOutputPath = normalizePath(outputPath);
6861
6894
  else {
6862
6895
  const excelDir = external_path_default().join(getStorageDir(), 'excel');
6863
6896
  await promises_namespaceObject.mkdir(excelDir, {
@@ -6866,6 +6899,10 @@ ${JSON.stringify(filteredData.slice(0, 3), null, 2)}
6866
6899
  const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
6867
6900
  finalOutputPath = external_path_default().join(excelDir, `export_${timestamp}.${options.format || 'xlsx'}`);
6868
6901
  }
6902
+ const outputDir = external_path_default().dirname(finalOutputPath);
6903
+ await promises_namespaceObject.mkdir(outputDir, {
6904
+ recursive: true
6905
+ });
6869
6906
  const buffer = external_xlsx_namespaceObject.write(workbook, {
6870
6907
  type: 'buffer',
6871
6908
  bookType: options.format || 'xlsx'
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/export-excel/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,uBAAuB;;;;;;;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"index.d.ts","sourceRoot":"","sources":["../../../src/services/read-excel/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUhC,CAAC;AAEH,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,GAAG,CAAC,EAAE,OAAO,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;CACL;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAIA,GAAG;;;;;;;;;;;;;CA+J5B,CAAC"}
@@ -10,8 +10,16 @@ export declare const sanitizeFileName: (input: string) => string;
10
10
  * @returns 不含图片的纯文本Markdown
11
11
  */
12
12
  export declare function removeImagesFromMarkdown(content: string): string;
13
+ /**
14
+ * 跨平台路径标准化处理
15
+ */
16
+ export declare function normalizePath(filePath: string): string;
13
17
  /**
14
18
  * 安全验证并标准化路径
15
19
  */
16
20
  export declare function validateAndResolvePath(filePath: string): Promise<string>;
21
+ /**
22
+ * 检查路径是否为有效的Excel文件
23
+ */
24
+ export declare function isValidExcelPath(filePath: string): boolean;
17
25
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CActC;AAED,iBAAiB;AACjB,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MAWhD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAiBhE;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkB9E"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CActC;AAED,iBAAiB;AACjB,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MAWhD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAiBhE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CA8BtD;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkB9E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAO1D"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * 跨平台路径工具集
3
+ * 提供Windows、Linux、macOS三平台的路径兼容性处理
4
+ */
5
+ export interface PathInfo {
6
+ original: string;
7
+ normalized: string;
8
+ absolute: string;
9
+ exists: boolean;
10
+ isFile: boolean;
11
+ isDirectory: boolean;
12
+ size?: number;
13
+ platform: string;
14
+ isValid: boolean;
15
+ }
16
+ /**
17
+ * 检测操作系统类型
18
+ */
19
+ export declare function getPlatformInfo(): {
20
+ platform: NodeJS.Platform;
21
+ arch: NodeJS.Architecture;
22
+ version: string;
23
+ cwd: string;
24
+ homedir: string;
25
+ tmpdir: string;
26
+ };
27
+ /**
28
+ * 检查路径是否为Windows路径
29
+ */
30
+ export declare function isWindowsPath(filePath: string): boolean;
31
+ /**
32
+ * 检查路径是否为Linux/macOS路径
33
+ */
34
+ export declare function isUnixPath(filePath: string): boolean;
35
+ /**
36
+ * 将Windows路径转换为Unix风格路径
37
+ */
38
+ export declare function windowsToUnixPath(filePath: string): string;
39
+ /**
40
+ * 将Unix路径转换为Windows路径
41
+ */
42
+ export declare function unixToWindowsPath(filePath: string): string;
43
+ /**
44
+ * 跨平台路径标准化
45
+ */
46
+ export declare function normalizeCrossPlatformPath(filePath: string): string;
47
+ /**
48
+ * 获取路径详细信息
49
+ */
50
+ export declare function getPathInfo(filePath: string): Promise<PathInfo>;
51
+ /**
52
+ * 验证路径是否可读
53
+ */
54
+ export declare function validatePathAccess(filePath: string): Promise<boolean>;
55
+ /**
56
+ * 检查是否为Excel文件路径
57
+ */
58
+ export declare function isExcelFilePath(filePath: string): boolean;
59
+ /**
60
+ * 安全地解析和验证文件路径
61
+ */
62
+ export declare function safeResolvePath(filePath: string): Promise<{
63
+ success: boolean;
64
+ resolvedPath?: string;
65
+ error?: string;
66
+ info?: PathInfo;
67
+ }>;
68
+ /**
69
+ * 获取跨平台路径兼容性建议
70
+ */
71
+ export declare function getPathCompatibilityAdvice(filePath: string): string[];
72
+ //# sourceMappingURL=path-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../../src/utils/path-utils.ts"],"names":[],"mappings":"AAMA;;;GAGG;AAEH,MAAM,WAAW,QAAQ;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,eAAe;;;;;;;EAS9B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAY1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAsB1D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAqCnE;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8BrE;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQ3E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAOzD;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7D,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAC,CAsCD;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CA0BrE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intention-coding",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "软件工程化的需求分析,功能设计,代码编写,测试运行和发布部署",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@10.11.0",