mcp-osp-prompt 1.0.0 → 1.0.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/README.md +22 -78
- package/config.js +12 -17
- package/debug-env.js +7 -0
- package/dialog/browser.js +2 -2
- package/dialog/constants.js +0 -2
- package/dialog/native.js +23 -34
- package/dialog/objc.js +2 -2
- package/fetcher.js +1 -1
- package/package.json +5 -5
- package/platform-utils.js +18 -45
- package/prompt-manager.js +89 -534
- package/server.js +58 -15
- package/test.js +2 -2
- package/tools.js +14 -147
- package/resource-manager.js +0 -358
package/platform-utils.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Shared between config.js and fetcher.js to avoid code duplication
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
// Platform detection from
|
|
6
|
+
// Platform detection from PROMPT_PATH
|
|
7
7
|
export function detectPlatformFromPath(promptPath) {
|
|
8
8
|
if (!promptPath) {
|
|
9
9
|
return null;
|
|
@@ -29,15 +29,14 @@ export function detectPlatformFromPath(promptPath) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// Parse remote path information with universal support for complex URLs
|
|
32
|
-
|
|
33
|
-
export function parseRemotePath(promptPath, subDirectory = '') {
|
|
32
|
+
export function parseRemotePath(promptPath) {
|
|
34
33
|
// 🟢 GREEN: Task 1.1 - 添加null/undefined检查和详细错误信息
|
|
35
34
|
if (!promptPath) {
|
|
36
|
-
throw new Error('
|
|
35
|
+
throw new Error('PROMPT_PATH cannot be null or empty. Please set a valid remote URL or local path.');
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
if (typeof promptPath !== 'string') {
|
|
40
|
-
throw new Error(`
|
|
39
|
+
throw new Error(`PROMPT_PATH must be a string, received: ${typeof promptPath}`);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
const cleanPath = promptPath.replace(/^https?:\/\//, '');
|
|
@@ -74,27 +73,27 @@ export function parseRemotePath(promptPath, subDirectory = '') {
|
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
return
|
|
76
|
+
return {
|
|
78
77
|
platform: 'github',
|
|
79
78
|
project,
|
|
80
79
|
repo: project, // Alias for backward compatibility
|
|
81
80
|
branch: branch || 'main',
|
|
82
81
|
path: path || '', // File/directory path
|
|
83
82
|
apiUrl: `https://api.github.com/repos/${project}/contents/${path || ''}`
|
|
84
|
-
}
|
|
83
|
+
};
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
// Match simple GitHub project URLs
|
|
88
87
|
const simpleMatch = cleanPath.match(/github\.com\/([^\/]+\/[^\/]+)/);
|
|
89
88
|
if (simpleMatch) {
|
|
90
|
-
return
|
|
89
|
+
return {
|
|
91
90
|
platform: 'github',
|
|
92
91
|
project: simpleMatch[1],
|
|
93
92
|
repo: simpleMatch[1],
|
|
94
93
|
branch: 'main',
|
|
95
94
|
path: '',
|
|
96
95
|
apiUrl: `https://api.github.com/repos/${simpleMatch[1]}/contents`
|
|
97
|
-
}
|
|
96
|
+
};
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
|
|
@@ -104,72 +103,46 @@ export function parseRemotePath(promptPath, subDirectory = '') {
|
|
|
104
103
|
const treeMatch = cleanPath.match(/gitlab\.com\/(.*?)\/-\/tree\/([^\/]+)\/?(.*)/);
|
|
105
104
|
if (treeMatch) {
|
|
106
105
|
const [, project, branch, path] = treeMatch;
|
|
107
|
-
return
|
|
106
|
+
return {
|
|
108
107
|
platform: 'gitlab',
|
|
109
108
|
project,
|
|
110
109
|
group: project, // Alias for backward compatibility
|
|
111
110
|
branch,
|
|
112
111
|
path: path || '', // File/directory path
|
|
113
112
|
apiUrl: `https://gitlab.com/api/v4/projects/${encodeURIComponent(project)}/repository/tree?path=${path || ''}&ref=${branch}&recursive=true&per_page=100`
|
|
114
|
-
}
|
|
113
|
+
};
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
// Match simple GitLab project URLs
|
|
118
117
|
const simpleMatch = cleanPath.match(/gitlab\.com\/(.+?)(?:\/|$)/);
|
|
119
118
|
if (simpleMatch) {
|
|
120
119
|
const project = simpleMatch[1];
|
|
121
|
-
return
|
|
120
|
+
return {
|
|
122
121
|
platform: 'gitlab',
|
|
123
122
|
project,
|
|
124
123
|
group: project,
|
|
125
124
|
branch: 'master',
|
|
126
125
|
path: '',
|
|
127
126
|
apiUrl: `https://gitlab.com/api/v4/projects/${encodeURIComponent(project)}/repository/tree?ref=master&recursive=true&per_page=100`
|
|
128
|
-
}
|
|
127
|
+
};
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
// Handle simple format like "user/repo" (defaults to GitHub)
|
|
133
132
|
if (promptPath.match(/^[\w-]+\/[\w-]+$/)) {
|
|
134
|
-
return
|
|
133
|
+
return {
|
|
135
134
|
platform: 'github',
|
|
136
135
|
project: promptPath,
|
|
137
136
|
repo: promptPath,
|
|
138
137
|
branch: 'main',
|
|
139
138
|
path: '',
|
|
140
139
|
apiUrl: `https://api.github.com/repos/${promptPath}/contents`
|
|
141
|
-
}
|
|
140
|
+
};
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
return null;
|
|
145
144
|
}
|
|
146
145
|
|
|
147
|
-
// 🟢 GREEN: Task 1.1 - 辅助函数:追加子目录到路径信息
|
|
148
|
-
function appendSubDirectory(pathInfo, subDirectory) {
|
|
149
|
-
if (!subDirectory || !pathInfo) {
|
|
150
|
-
return pathInfo;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// 追加子目录到path
|
|
154
|
-
const newPath = pathInfo.path ? `${pathInfo.path}/${subDirectory}` : subDirectory;
|
|
155
|
-
|
|
156
|
-
// 根据平台更新apiUrl
|
|
157
|
-
let newApiUrl = pathInfo.apiUrl;
|
|
158
|
-
if (pathInfo.platform === 'github') {
|
|
159
|
-
// GitHub: https://api.github.com/repos/{project}/contents/{path}
|
|
160
|
-
newApiUrl = `https://api.github.com/repos/${pathInfo.project}/contents/${newPath}`;
|
|
161
|
-
} else if (pathInfo.platform === 'gitlab') {
|
|
162
|
-
// GitLab: https://gitlab.com/api/v4/projects/{project}/repository/tree?path={path}&ref={branch}&recursive=true&per_page=100
|
|
163
|
-
newApiUrl = `https://gitlab.com/api/v4/projects/${encodeURIComponent(pathInfo.project)}/repository/tree?path=${newPath}&ref=${pathInfo.branch}&recursive=true&per_page=100`;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
...pathInfo,
|
|
168
|
-
path: newPath,
|
|
169
|
-
apiUrl: newApiUrl
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
146
|
// Create authentication headers based on platform
|
|
174
147
|
export function createAuthHeaders(platform, token) {
|
|
175
148
|
if (!token) {
|
|
@@ -191,12 +164,12 @@ export function createAuthHeaders(platform, token) {
|
|
|
191
164
|
}
|
|
192
165
|
|
|
193
166
|
// Validate configuration for given platform
|
|
194
|
-
export function validatePlatformConfiguration(
|
|
195
|
-
if (!
|
|
196
|
-
throw new Error('
|
|
167
|
+
export function validatePlatformConfiguration(promptPath, token) {
|
|
168
|
+
if (!promptPath) {
|
|
169
|
+
throw new Error('PROMPT_PATH is required. Set it to a local directory path, GitHub repo (user/repo), or full URL.');
|
|
197
170
|
}
|
|
198
171
|
|
|
199
|
-
const platform = detectPlatformFromPath(
|
|
172
|
+
const platform = detectPlatformFromPath(promptPath);
|
|
200
173
|
|
|
201
174
|
if ((platform === 'github' || platform === 'gitlab') && !token) {
|
|
202
175
|
throw new Error('GIT_TOKEN is required for remote repositories. Please set your GitHub or GitLab access token.');
|