phinix 0.0.4 → 0.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phinix",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "phinix - A Model Context Protocol server for managing and generating React components",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -9,6 +9,7 @@
9
9
  - **UI 组件库**: DPAntd (定制化 Ant Design)
10
10
  - **路由**: React Router DOM
11
11
  - **图标**: AliIcon (@ali/icon)
12
+ - **公共方法**: DPUtils(全局可用,无需导入)
12
13
 
13
14
  ## 代码规范
14
15
  以下是项目的代码规范,必须要遵循!
@@ -19,6 +20,13 @@
19
20
  - 非常重要:优先使用get_component_list获取到的组件,如果没有符合条件的组件,再使用DPAntd中的组件
20
21
  - 非常重要:单文件代码行数不得超过300行,如果超过必须拆分
21
22
  - 非常重要:枚举定义、interface定义等代码放到一个单独的define.ts文件中
23
+ - 非常重要:所有文件顶部需要包含文件描述和作者信息${author},例如
24
+ ```js
25
+ /**
26
+ * @description 组件的描述
27
+ * @author ${author}
28
+ */
29
+ ```
22
30
 
23
31
  ## 🎨 样式规范
24
32
  - 非常重要:优先使用tailwind完成样式开发
@@ -69,6 +77,41 @@ import { slice } from "@alife/raft"; // Raft方法全局可用
69
77
  - 重要:slice中的状态都需要添加注释说明
70
78
 
71
79
  - 非常重要:raft相关的所有方法全局可用,不需要导入
80
+ - 非常重要:slice文件格式要和使用示例相同
81
+ - 非常重要:slice使用时,需要和示例相同,先将state结构出来再进行使用
82
+
83
+ ### 使用示例
84
+ #### slice文件
85
+ ```tsx
86
+ /**
87
+ * @author 作者
88
+ * @description 对话式AI,反馈组件(点赞、点踩) slice
89
+ */
90
+ export const AIFeedbackSlice = slice(({ set }) => ({
91
+ /** 反馈结果 */
92
+ feedbackResult: API.metaCenter.aiFeedback.postMessageFeedback.initFetchResult(),
93
+
94
+ /** 反馈 */
95
+ feedback: API.metaCenter.aiFeedback.postMessageFeedback.createSliceAction(set, 'feedbackResult'),
96
+
97
+ /** 内部的反馈类型 */
98
+ innerFeedbackType: '' as 'LIKE' | 'DISLIKE' | '',
99
+
100
+ /** 是否展示反馈popover */
101
+ isShowFeedbackPopover: false,
102
+
103
+ /** 反馈标签 */
104
+ feedbackTags: [] as string[],
105
+
106
+ /** 反馈文本 */
107
+ feedbackText: '',
108
+ }));
109
+ ```
110
+ #### slice使用:
111
+ ``` tsx
112
+ const [{ feedback, innerFeedbackType, feedbackTags, feedbackText, isShowFeedbackPopover, feedbackResult }, setState] =
113
+ useStateSlice(SliceName);
114
+ ```
72
115
 
73
116
  ## 📝 文本处理规范
74
117
 
@@ -3,10 +3,39 @@ import path from "path";
3
3
  import { z } from "zod";
4
4
  import { __dirname } from "../config.js";
5
5
 
6
- export const projectKnowledgeSchema = {};
6
+ // 获取作者信息,参照config.js中获取项目根目录的逻辑
7
+ function getAuthor() {
8
+ // 优先级:命令行参数 > 环境变量 > 默认空字符串
9
+ const args = process.argv.slice(2);
10
+
11
+ // 检查命名参数 --author=name
12
+ const authorArg = args.find((arg) => arg.startsWith("--author="));
13
+ if (authorArg) {
14
+ return authorArg.split("=")[1];
15
+ }
16
+
17
+ // 检查环境变量
18
+ if (process.env.AUTHOR) {
19
+ return process.env.AUTHOR;
20
+ }
21
+
22
+ // 默认返回空字符串
23
+ return "";
24
+ }
25
+
26
+ export const projectKnowledgeSchema = {
27
+ author: {
28
+ type: "string",
29
+ description: "作者信息,将替换项目背景知识中的${author}占位符。优先级:参数 > --author命令行参数 > AUTHOR环境变量 > 空字符串",
30
+ default: ""
31
+ }
32
+ };
7
33
 
8
34
  export async function getProjectKnowledge(params) {
9
35
  try {
36
+ // 获取作者信息,优先级:传入参数 > 命令行参数 > 环境变量 > 默认空字符串
37
+ const author = params.author !== undefined ? params.author : getAuthor();
38
+
10
39
  // 尝试多个可能的文件路径
11
40
  const possiblePaths = [
12
41
  path.join(__dirname, "resources/project-knowledge.md"),
@@ -37,6 +66,9 @@ export async function getProjectKnowledge(params) {
37
66
  );
38
67
  }
39
68
 
69
+ // 替换文件内容中的${author}占位符
70
+ const processedContent = fileContent.replace(/\$\{author\}/g, author);
71
+
40
72
  // 在第一次成功加载时记录路径
41
73
  if (!global._knowledgePath) {
42
74
  global._knowledgePath = knowledgePath;
@@ -47,11 +79,15 @@ export async function getProjectKnowledge(params) {
47
79
  content: [
48
80
  {
49
81
  type: "text",
50
- text: fileContent,
82
+ text: processedContent,
51
83
  },
52
84
  ],
53
85
  data: {
54
86
  filePath: knowledgePath,
87
+ author: author,
88
+ authorSource: params.author !== undefined ? "parameter" :
89
+ process.argv.find(arg => arg.startsWith("--author=")) ? "command-line" :
90
+ process.env.AUTHOR ? "environment" : "default",
55
91
  timestamp: new Date().toISOString(),
56
92
  },
57
93
  };