zen-gitsync 2.16.28 → 2.16.30
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 +2 -2
- package/package.json +1 -1
- package/src/cli/ai/platformGuard.js +200 -200
- package/src/cli/ai/platformGuard.test.js +253 -253
- package/src/gitCommit.js +484 -484
- package/src/ui/public/assets/AgentView-Cp9Xgs_B.js +4 -0
- package/src/ui/public/assets/AppVersionBadge-DcgY2eSV.js +2 -0
- package/src/ui/public/assets/BranchSelector-Bc_nwnaf.js +1 -0
- package/src/ui/public/assets/CommitForm-DmTaYwYF.js +6 -0
- package/src/ui/public/assets/CommonDialog-Brk9ZIx_.js +1 -0
- package/src/ui/public/assets/EditorView-BXcPstel.js +1 -0
- package/src/ui/public/assets/{FlowExecutionViewer-B7CdeiSp.js → FlowExecutionViewer-DT4WJ3H6.js} +1 -1
- package/src/ui/public/assets/FlowOrchestrationWorkspace-kzpWFreh.js +21 -0
- package/src/ui/public/assets/LogList-BlJplIi1.css +1 -0
- package/src/ui/public/assets/LogList-FyPUAVK6.js +7 -0
- package/src/ui/public/assets/MindmapView-qul1kc2j.js +2 -0
- package/src/ui/public/assets/MonitorView-CJO-jTlG.js +1 -0
- package/src/ui/public/assets/ProjectStartupButton-oZJIaL1F.js +1 -0
- package/src/ui/public/assets/{RemoteRepoCard-CGn4tRy-.js → RemoteRepoCard-Cyz5QDia.js} +2 -2
- package/src/ui/public/assets/SourceMapView-BXHG1JE_.js +3 -0
- package/src/ui/public/assets/{SvgIcon-CL2qPswh.js → SvgIcon-DjCKMwo1.js} +1 -1
- package/src/ui/public/assets/UserInputNode-lSHdQ7nQ.js +1 -0
- package/src/ui/public/assets/WorkbenchView-BSupsbko.js +28 -0
- package/src/ui/public/assets/{_plugin-vue_export-helper-D3_upOKo.js → _plugin-vue_export-helper-DExUTKTW.js} +5 -3
- package/src/ui/public/assets/configStore-BFc69UjA.js +1 -0
- package/src/ui/public/assets/{css.worker-CvXBzhp8.js → css.worker-Wv5dxAWO.js} +1 -1
- package/src/ui/public/assets/{dagre-CWIGcX9d.js → dagre-CyRyf1aT.js} +1 -1
- package/src/ui/public/assets/element-plus--ayTjGvF.js +25 -0
- package/src/ui/public/assets/element-plus-D3Dn7nX0.css +1 -0
- package/src/ui/public/assets/{flow-mindmap-B5aqOviR.js → flow-mindmap-BcBVGR99.js} +38 -38
- package/src/ui/public/assets/{html.worker-BO6WuOEO.js → html.worker-CQP8QQsS.js} +1 -1
- package/src/ui/public/assets/index-DX3FHIo4.js +79 -0
- package/src/ui/public/assets/index-zmReBTKj.css +1 -0
- package/src/ui/public/assets/{json.worker-BkJRGcCJ.js → json.worker-DzV-CpCQ.js} +1 -1
- package/src/ui/public/assets/{monaco-BFLoT2VD.js → monaco-43aputPh.js} +198 -198
- package/src/ui/public/assets/socket-io-BZIzo1US.js +1 -0
- package/src/ui/public/assets/toolsStore-B2zt5KJ0.js +1 -0
- package/src/ui/public/assets/{ts.worker-B0J26iPs.js → ts.worker-Dth06zuC.js} +15 -15
- package/src/ui/public/assets/{vendor-Cx8PA1NP.js → vendor-Dan_vdyX.js} +14 -14
- package/src/ui/public/assets/{vue-flow-COROsN-V.js → vue-flow-CUR1dbQb.js} +2 -2
- package/src/ui/public/favicon.svg +75 -75
- package/src/ui/public/index.html +32 -32
- package/src/ui/public/logo.svg +74 -74
- package/src/ui/server/middleware/requestLogger.js +53 -53
- package/src/ui/server/routes/branchStatus.js +105 -105
- package/src/ui/server/routes/git/diff.js +426 -426
- package/src/ui/server/routes/git/diffUtils.js +149 -149
- package/src/ui/server/routes/git/stash.js +550 -550
- package/src/ui/server/routes/git/tags.js +176 -176
- package/src/ui/server/routes/process.js +86 -86
- package/src/ui/server/routes/status.js +67 -67
- package/src/ui/server/routes/workbench/pdfText.js +145 -145
- package/src/ui/server/utils/createSavePortToFile.js +48 -48
- package/src/ui/server/utils/instanceRegistry.js +282 -282
- package/src/ui/server/utils/startServerOnAvailablePort.js +116 -116
- package/src/ui/public/assets/AgentView-Bytr0HbV.js +0 -4
- package/src/ui/public/assets/AppVersionBadge-DTsgbuSQ.js +0 -2
- package/src/ui/public/assets/BranchSelector-C9OPOmaJ.js +0 -1
- package/src/ui/public/assets/CommitForm-Cr5Ajewf.js +0 -6
- package/src/ui/public/assets/CommonDialog-CQz6iEqp.js +0 -1
- package/src/ui/public/assets/EditorView-BYoWEp7_.js +0 -1
- package/src/ui/public/assets/FlowOrchestrationWorkspace--Sguba2_.js +0 -21
- package/src/ui/public/assets/LogList-Bo53PBwg.css +0 -1
- package/src/ui/public/assets/LogList-CF47CGZw.js +0 -7
- package/src/ui/public/assets/MindmapView-DR5bT_oQ.js +0 -2
- package/src/ui/public/assets/MonitorView-DoLNabxl.js +0 -1
- package/src/ui/public/assets/ProjectStartupButton-BiNiH43W.js +0 -1
- package/src/ui/public/assets/SourceMapView-DhxMPULM.js +0 -3
- package/src/ui/public/assets/UserInputNode-BftMuqji.js +0 -1
- package/src/ui/public/assets/WorkbenchView-CJwU_MsO.js +0 -28
- package/src/ui/public/assets/configStore-Cqnbpz5-.js +0 -1
- package/src/ui/public/assets/element-plus-B3pTS_5R.js +0 -32
- package/src/ui/public/assets/element-plus-CQrjg9us.css +0 -1
- package/src/ui/public/assets/index-BgKFctmf.js +0 -71
- package/src/ui/public/assets/index-DnD8_s3s.css +0 -1
- package/src/ui/public/assets/socket-io-Bcae2P7B.js +0 -1
- package/src/ui/public/assets/toolsStore-D9gXnqwO.js +0 -1
- package/src/ui/server/.claude/codediff.txt +0 -8
- /package/src/ui/public/assets/{editor.worker-Cn2oRESe.js → editor.worker-Bd9IXS8d.js} +0 -0
- /package/src/ui/public/assets/{rolldown-runtime-CMxvf4Kt.js → rolldown-runtime-BM3Ffeng.js} +0 -0
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
// Copyright 2026 xz333221
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
//
|
|
15
|
-
import { asyncRoute, HttpError } from '../../utils/asyncRoute.js'
|
|
16
|
-
|
|
17
|
-
import logger from '../../utils/logger.js'
|
|
18
|
-
|
|
19
|
-
export function registerGitTagRoutes({ app, execGitCommand, clearCommandHistory }) {
|
|
20
|
-
// ============ Git Tag 相关接口 ============
|
|
21
|
-
|
|
22
|
-
// 创建标签
|
|
23
|
-
app.post('/api/create-tag', asyncRoute(async (req, res) => {
|
|
24
|
-
try {
|
|
25
|
-
const { tagName, message, type, commit } = req.body;
|
|
26
|
-
|
|
27
|
-
if (!tagName) {
|
|
28
|
-
throw new HttpError(400, '缺少标签名称');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const tagArgs = ['tag'];
|
|
32
|
-
|
|
33
|
-
if (type === 'annotated') {
|
|
34
|
-
// 附注标签
|
|
35
|
-
if (!message) {
|
|
36
|
-
throw new HttpError(400, '附注标签需要提供说明信息');
|
|
37
|
-
}
|
|
38
|
-
tagArgs.push('-a', tagName, '-m', message);
|
|
39
|
-
} else {
|
|
40
|
-
// 轻量标签
|
|
41
|
-
tagArgs.push(tagName);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 如果指定了commit,添加到命令中
|
|
45
|
-
if (commit && commit.trim()) {
|
|
46
|
-
tagArgs.push(commit.trim());
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const { stdout } = await execGitCommand(tagArgs);
|
|
50
|
-
|
|
51
|
-
res.json({
|
|
52
|
-
success: true,
|
|
53
|
-
message: '标签创建成功',
|
|
54
|
-
output: stdout
|
|
55
|
-
});
|
|
56
|
-
} catch (error) {
|
|
57
|
-
logger.error('创建标签失败:', error);
|
|
58
|
-
res.status(500).json({ success: false, error: error.message });
|
|
59
|
-
}
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
// 获取标签列表
|
|
63
|
-
app.get('/api/list-tags', asyncRoute(async (req, res) => {
|
|
64
|
-
try {
|
|
65
|
-
// 使用 git tag -n --format 获取详细信息
|
|
66
|
-
const { stdout } = await execGitCommand(
|
|
67
|
-
['tag', '-n', '--format=%(refname:short)|%(objectname:short)|%(creatordate:iso8601)|%(subject)']
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
if (!stdout.trim()) {
|
|
71
|
-
return res.json({ success: true, tags: [] });
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const tags = stdout.trim().split('\n').map(line => {
|
|
75
|
-
const [name, commit, date, message] = line.split('|');
|
|
76
|
-
return {
|
|
77
|
-
name: name || '',
|
|
78
|
-
commit: commit || '',
|
|
79
|
-
date: date || '',
|
|
80
|
-
message: message || '',
|
|
81
|
-
type: 'lightweight' // 默认为轻量标签
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// 检测哪些是附注标签
|
|
86
|
-
for (const tag of tags) {
|
|
87
|
-
try {
|
|
88
|
-
const { stdout: typeCheck } = await execGitCommand(
|
|
89
|
-
['cat-file', '-t', tag.name],
|
|
90
|
-
{ log: false }
|
|
91
|
-
);
|
|
92
|
-
if (typeCheck.trim() === 'tag') {
|
|
93
|
-
tag.type = 'annotated';
|
|
94
|
-
}
|
|
95
|
-
} catch (error) {
|
|
96
|
-
// 忽略错误,保持默认值
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
res.json({ success: true, tags });
|
|
101
|
-
} catch (error) {
|
|
102
|
-
logger.error('获取标签列表失败:', error);
|
|
103
|
-
res.status(500).json({ success: false, error: error.message });
|
|
104
|
-
}
|
|
105
|
-
}));
|
|
106
|
-
|
|
107
|
-
// 推送标签到远程
|
|
108
|
-
app.post('/api/push-tag', asyncRoute(async (req, res) => {
|
|
109
|
-
try {
|
|
110
|
-
const { tagName } = req.body;
|
|
111
|
-
|
|
112
|
-
if (!tagName) {
|
|
113
|
-
throw new HttpError(400, '缺少标签名称');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const { stdout } = await execGitCommand(['push', 'origin', tagName]);
|
|
117
|
-
|
|
118
|
-
res.json({
|
|
119
|
-
success: true,
|
|
120
|
-
message: '标签推送成功',
|
|
121
|
-
output: stdout
|
|
122
|
-
});
|
|
123
|
-
} catch (error) {
|
|
124
|
-
logger.error('推送标签失败:', error);
|
|
125
|
-
res.status(500).json({ success: false, error: error.message });
|
|
126
|
-
}
|
|
127
|
-
}));
|
|
128
|
-
|
|
129
|
-
// 推送所有标签到远程
|
|
130
|
-
app.post('/api/push-all-tags', asyncRoute(async (req, res) => {
|
|
131
|
-
try {
|
|
132
|
-
const { stdout } = await execGitCommand(['push', 'origin', '--tags']);
|
|
133
|
-
|
|
134
|
-
res.json({
|
|
135
|
-
success: true,
|
|
136
|
-
message: '所有标签推送成功',
|
|
137
|
-
output: stdout
|
|
138
|
-
});
|
|
139
|
-
} catch (error) {
|
|
140
|
-
logger.error('推送所有标签失败:', error);
|
|
141
|
-
res.status(500).json({ success: false, error: error.message });
|
|
142
|
-
}
|
|
143
|
-
}));
|
|
144
|
-
|
|
145
|
-
// 删除标签
|
|
146
|
-
app.post('/api/delete-tag', asyncRoute(async (req, res) => {
|
|
147
|
-
try {
|
|
148
|
-
const { tagName } = req.body;
|
|
149
|
-
|
|
150
|
-
if (!tagName) {
|
|
151
|
-
throw new HttpError(400, '缺少标签名称');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const { stdout } = await execGitCommand(['tag', '-d', tagName]);
|
|
155
|
-
|
|
156
|
-
res.json({
|
|
157
|
-
success: true,
|
|
158
|
-
message: '标签删除成功',
|
|
159
|
-
output: stdout
|
|
160
|
-
});
|
|
161
|
-
} catch (error) {
|
|
162
|
-
logger.error('删除标签失败:', error);
|
|
163
|
-
res.status(500).json({ success: false, error: error.message });
|
|
164
|
-
}
|
|
165
|
-
}));
|
|
166
|
-
|
|
167
|
-
// 添加命令历史的清空API
|
|
168
|
-
app.post('/api/clear-command-history', asyncRoute(async (req, res) => {
|
|
169
|
-
try {
|
|
170
|
-
const result = clearCommandHistory();
|
|
171
|
-
res.json({ success: result });
|
|
172
|
-
} catch (error) {
|
|
173
|
-
res.status(500).json({ success: false, error: error.message });
|
|
174
|
-
}
|
|
175
|
-
}));
|
|
176
|
-
}
|
|
1
|
+
// Copyright 2026 xz333221
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
import { asyncRoute, HttpError } from '../../utils/asyncRoute.js'
|
|
16
|
+
|
|
17
|
+
import logger from '../../utils/logger.js'
|
|
18
|
+
|
|
19
|
+
export function registerGitTagRoutes({ app, execGitCommand, clearCommandHistory }) {
|
|
20
|
+
// ============ Git Tag 相关接口 ============
|
|
21
|
+
|
|
22
|
+
// 创建标签
|
|
23
|
+
app.post('/api/create-tag', asyncRoute(async (req, res) => {
|
|
24
|
+
try {
|
|
25
|
+
const { tagName, message, type, commit } = req.body;
|
|
26
|
+
|
|
27
|
+
if (!tagName) {
|
|
28
|
+
throw new HttpError(400, '缺少标签名称');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const tagArgs = ['tag'];
|
|
32
|
+
|
|
33
|
+
if (type === 'annotated') {
|
|
34
|
+
// 附注标签
|
|
35
|
+
if (!message) {
|
|
36
|
+
throw new HttpError(400, '附注标签需要提供说明信息');
|
|
37
|
+
}
|
|
38
|
+
tagArgs.push('-a', tagName, '-m', message);
|
|
39
|
+
} else {
|
|
40
|
+
// 轻量标签
|
|
41
|
+
tagArgs.push(tagName);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 如果指定了commit,添加到命令中
|
|
45
|
+
if (commit && commit.trim()) {
|
|
46
|
+
tagArgs.push(commit.trim());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const { stdout } = await execGitCommand(tagArgs);
|
|
50
|
+
|
|
51
|
+
res.json({
|
|
52
|
+
success: true,
|
|
53
|
+
message: '标签创建成功',
|
|
54
|
+
output: stdout
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
logger.error('创建标签失败:', error);
|
|
58
|
+
res.status(500).json({ success: false, error: error.message });
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
// 获取标签列表
|
|
63
|
+
app.get('/api/list-tags', asyncRoute(async (req, res) => {
|
|
64
|
+
try {
|
|
65
|
+
// 使用 git tag -n --format 获取详细信息
|
|
66
|
+
const { stdout } = await execGitCommand(
|
|
67
|
+
['tag', '-n', '--format=%(refname:short)|%(objectname:short)|%(creatordate:iso8601)|%(subject)']
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
if (!stdout.trim()) {
|
|
71
|
+
return res.json({ success: true, tags: [] });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const tags = stdout.trim().split('\n').map(line => {
|
|
75
|
+
const [name, commit, date, message] = line.split('|');
|
|
76
|
+
return {
|
|
77
|
+
name: name || '',
|
|
78
|
+
commit: commit || '',
|
|
79
|
+
date: date || '',
|
|
80
|
+
message: message || '',
|
|
81
|
+
type: 'lightweight' // 默认为轻量标签
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// 检测哪些是附注标签
|
|
86
|
+
for (const tag of tags) {
|
|
87
|
+
try {
|
|
88
|
+
const { stdout: typeCheck } = await execGitCommand(
|
|
89
|
+
['cat-file', '-t', tag.name],
|
|
90
|
+
{ log: false }
|
|
91
|
+
);
|
|
92
|
+
if (typeCheck.trim() === 'tag') {
|
|
93
|
+
tag.type = 'annotated';
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
// 忽略错误,保持默认值
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
res.json({ success: true, tags });
|
|
101
|
+
} catch (error) {
|
|
102
|
+
logger.error('获取标签列表失败:', error);
|
|
103
|
+
res.status(500).json({ success: false, error: error.message });
|
|
104
|
+
}
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
// 推送标签到远程
|
|
108
|
+
app.post('/api/push-tag', asyncRoute(async (req, res) => {
|
|
109
|
+
try {
|
|
110
|
+
const { tagName } = req.body;
|
|
111
|
+
|
|
112
|
+
if (!tagName) {
|
|
113
|
+
throw new HttpError(400, '缺少标签名称');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const { stdout } = await execGitCommand(['push', 'origin', tagName]);
|
|
117
|
+
|
|
118
|
+
res.json({
|
|
119
|
+
success: true,
|
|
120
|
+
message: '标签推送成功',
|
|
121
|
+
output: stdout
|
|
122
|
+
});
|
|
123
|
+
} catch (error) {
|
|
124
|
+
logger.error('推送标签失败:', error);
|
|
125
|
+
res.status(500).json({ success: false, error: error.message });
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
// 推送所有标签到远程
|
|
130
|
+
app.post('/api/push-all-tags', asyncRoute(async (req, res) => {
|
|
131
|
+
try {
|
|
132
|
+
const { stdout } = await execGitCommand(['push', 'origin', '--tags']);
|
|
133
|
+
|
|
134
|
+
res.json({
|
|
135
|
+
success: true,
|
|
136
|
+
message: '所有标签推送成功',
|
|
137
|
+
output: stdout
|
|
138
|
+
});
|
|
139
|
+
} catch (error) {
|
|
140
|
+
logger.error('推送所有标签失败:', error);
|
|
141
|
+
res.status(500).json({ success: false, error: error.message });
|
|
142
|
+
}
|
|
143
|
+
}));
|
|
144
|
+
|
|
145
|
+
// 删除标签
|
|
146
|
+
app.post('/api/delete-tag', asyncRoute(async (req, res) => {
|
|
147
|
+
try {
|
|
148
|
+
const { tagName } = req.body;
|
|
149
|
+
|
|
150
|
+
if (!tagName) {
|
|
151
|
+
throw new HttpError(400, '缺少标签名称');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const { stdout } = await execGitCommand(['tag', '-d', tagName]);
|
|
155
|
+
|
|
156
|
+
res.json({
|
|
157
|
+
success: true,
|
|
158
|
+
message: '标签删除成功',
|
|
159
|
+
output: stdout
|
|
160
|
+
});
|
|
161
|
+
} catch (error) {
|
|
162
|
+
logger.error('删除标签失败:', error);
|
|
163
|
+
res.status(500).json({ success: false, error: error.message });
|
|
164
|
+
}
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
// 添加命令历史的清空API
|
|
168
|
+
app.post('/api/clear-command-history', asyncRoute(async (req, res) => {
|
|
169
|
+
try {
|
|
170
|
+
const result = clearCommandHistory();
|
|
171
|
+
res.json({ success: result });
|
|
172
|
+
} catch (error) {
|
|
173
|
+
res.status(500).json({ success: false, error: error.message });
|
|
174
|
+
}
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
// Copyright 2026 xz333221
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
//
|
|
15
|
-
import { asyncRoute, HttpError } from '../utils/asyncRoute.js'
|
|
16
|
-
|
|
17
|
-
import logger from '../utils/logger.js'
|
|
18
|
-
|
|
19
|
-
export function registerProcessRoutes({
|
|
20
|
-
app,
|
|
21
|
-
runningProcesses,
|
|
22
|
-
exec
|
|
23
|
-
}) {
|
|
24
|
-
// 停止正在运行的进程
|
|
25
|
-
app.post('/api/kill-process', asyncRoute(async (req, res) => {
|
|
26
|
-
try {
|
|
27
|
-
const { processId } = req.body || {};
|
|
28
|
-
if (!processId || typeof processId !== 'number') {
|
|
29
|
-
throw new HttpError(400, 'processId 必须是数字');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const processInfo = runningProcesses.get(processId);
|
|
33
|
-
if (!processInfo) {
|
|
34
|
-
return res.status(404).json({
|
|
35
|
-
success: false,
|
|
36
|
-
error: `进程 #${processId} 不存在或已结束`
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
logger.info(`[进程管理] 尝试停止进程 #${processId}: ${processInfo.command}`);
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
// 在 Windows 上需要使用 taskkill 来杀死整个进程树
|
|
44
|
-
if (process.platform === 'win32') {
|
|
45
|
-
// 使用已导入的 exec
|
|
46
|
-
// /F 强制终止, /T 终止进程树
|
|
47
|
-
exec(`taskkill /pid ${processInfo.childProcess.pid} /T /F`, { windowsHide: true }, (error) => {
|
|
48
|
-
if (error) {
|
|
49
|
-
logger.error(`[进程管理] taskkill 失败:`, error);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
// Unix/Linux/Mac 使用 SIGTERM
|
|
54
|
-
processInfo.childProcess.kill('SIGTERM');
|
|
55
|
-
|
|
56
|
-
// 如果 2 秒后还没结束,使用 SIGKILL 强制终止
|
|
57
|
-
setTimeout(() => {
|
|
58
|
-
if (runningProcesses.has(processId)) {
|
|
59
|
-
logger.info(`[进程管理] 进程 #${processId} 未响应 SIGTERM,使用 SIGKILL 强制终止`);
|
|
60
|
-
processInfo.childProcess.kill('SIGKILL');
|
|
61
|
-
}
|
|
62
|
-
}, 2000);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
res.json({
|
|
66
|
-
success: true,
|
|
67
|
-
message: `已发送停止信号到进程 #${processId}`,
|
|
68
|
-
processId,
|
|
69
|
-
command: processInfo.command
|
|
70
|
-
});
|
|
71
|
-
} catch (killError) {
|
|
72
|
-
logger.error(`[进程管理] 停止进程失败:`, killError);
|
|
73
|
-
res.status(500).json({
|
|
74
|
-
success: false,
|
|
75
|
-
error: `停止进程失败: ${killError.message}`
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
logger.error('停止进程接口失败:', error);
|
|
80
|
-
res.status(500).json({
|
|
81
|
-
success: false,
|
|
82
|
-
error: `停止进程失败: ${error.message}`
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
1
|
+
// Copyright 2026 xz333221
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
import { asyncRoute, HttpError } from '../utils/asyncRoute.js'
|
|
16
|
+
|
|
17
|
+
import logger from '../utils/logger.js'
|
|
18
|
+
|
|
19
|
+
export function registerProcessRoutes({
|
|
20
|
+
app,
|
|
21
|
+
runningProcesses,
|
|
22
|
+
exec
|
|
23
|
+
}) {
|
|
24
|
+
// 停止正在运行的进程
|
|
25
|
+
app.post('/api/kill-process', asyncRoute(async (req, res) => {
|
|
26
|
+
try {
|
|
27
|
+
const { processId } = req.body || {};
|
|
28
|
+
if (!processId || typeof processId !== 'number') {
|
|
29
|
+
throw new HttpError(400, 'processId 必须是数字');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const processInfo = runningProcesses.get(processId);
|
|
33
|
+
if (!processInfo) {
|
|
34
|
+
return res.status(404).json({
|
|
35
|
+
success: false,
|
|
36
|
+
error: `进程 #${processId} 不存在或已结束`
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
logger.info(`[进程管理] 尝试停止进程 #${processId}: ${processInfo.command}`);
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
// 在 Windows 上需要使用 taskkill 来杀死整个进程树
|
|
44
|
+
if (process.platform === 'win32') {
|
|
45
|
+
// 使用已导入的 exec
|
|
46
|
+
// /F 强制终止, /T 终止进程树
|
|
47
|
+
exec(`taskkill /pid ${processInfo.childProcess.pid} /T /F`, { windowsHide: true }, (error) => {
|
|
48
|
+
if (error) {
|
|
49
|
+
logger.error(`[进程管理] taskkill 失败:`, error);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
// Unix/Linux/Mac 使用 SIGTERM
|
|
54
|
+
processInfo.childProcess.kill('SIGTERM');
|
|
55
|
+
|
|
56
|
+
// 如果 2 秒后还没结束,使用 SIGKILL 强制终止
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
if (runningProcesses.has(processId)) {
|
|
59
|
+
logger.info(`[进程管理] 进程 #${processId} 未响应 SIGTERM,使用 SIGKILL 强制终止`);
|
|
60
|
+
processInfo.childProcess.kill('SIGKILL');
|
|
61
|
+
}
|
|
62
|
+
}, 2000);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
res.json({
|
|
66
|
+
success: true,
|
|
67
|
+
message: `已发送停止信号到进程 #${processId}`,
|
|
68
|
+
processId,
|
|
69
|
+
command: processInfo.command
|
|
70
|
+
});
|
|
71
|
+
} catch (killError) {
|
|
72
|
+
logger.error(`[进程管理] 停止进程失败:`, killError);
|
|
73
|
+
res.status(500).json({
|
|
74
|
+
success: false,
|
|
75
|
+
error: `停止进程失败: ${killError.message}`
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger.error('停止进程接口失败:', error);
|
|
80
|
+
res.status(500).json({
|
|
81
|
+
success: false,
|
|
82
|
+
error: `停止进程失败: ${error.message}`
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
// Copyright 2026 xz333221
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
//
|
|
15
|
-
import { promises as fs } from 'fs';
|
|
16
|
-
import { asyncRoute, HttpError } from '../utils/asyncRoute.js';
|
|
17
|
-
import path from 'path';
|
|
18
|
-
|
|
19
|
-
export function registerStatusRoutes({
|
|
20
|
-
app,
|
|
21
|
-
getCommandHistory,
|
|
22
|
-
execGitCommand
|
|
23
|
-
}) {
|
|
24
|
-
// Add new endpoint for command history
|
|
25
|
-
app.get('/api/command-history', asyncRoute(async (req, res) => {
|
|
26
|
-
try {
|
|
27
|
-
const history = getCommandHistory();
|
|
28
|
-
res.json({ success: true, history });
|
|
29
|
-
} catch (error) {
|
|
30
|
-
res.status(500).json({ success: false, error: error.message });
|
|
31
|
-
}
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
app.get('/api/status_porcelain', asyncRoute(async (req, res) => {
|
|
35
|
-
try {
|
|
36
|
-
const { stdout } = await execGitCommand(['status', '--porcelain', '--untracked-files=all']);
|
|
37
|
-
// 检测是否处于 MERGING 状态(MERGE_HEAD 存在)
|
|
38
|
-
let isMergeInProgress = false;
|
|
39
|
-
let mergeMessage = '';
|
|
40
|
-
try {
|
|
41
|
-
const { stdout: mergeHead } = await execGitCommand(['rev-parse', '-q', '--verify', 'MERGE_HEAD']);
|
|
42
|
-
isMergeInProgress = mergeHead.trim().length > 0;
|
|
43
|
-
} catch (_) {
|
|
44
|
-
// MERGE_HEAD 不存在时命令会报错,属正常情况
|
|
45
|
-
isMergeInProgress = false;
|
|
46
|
-
}
|
|
47
|
-
if (isMergeInProgress) {
|
|
48
|
-
try {
|
|
49
|
-
const { stdout: gitDir } = await execGitCommand(['rev-parse', '--git-dir']);
|
|
50
|
-
const mergeMsgPath = path.resolve(gitDir.trim(), 'MERGE_MSG');
|
|
51
|
-
const raw = await fs.readFile(mergeMsgPath, 'utf-8');
|
|
52
|
-
// 过滤掉以 # 开头的注释行,拼接所有非空非注释行(保留多段信息如合并分支列表)
|
|
53
|
-
mergeMessage = raw
|
|
54
|
-
.split('\n')
|
|
55
|
-
.filter(line => line.trim() && !line.startsWith('#'))
|
|
56
|
-
.join('\n')
|
|
57
|
-
.trim();
|
|
58
|
-
} catch (_) {
|
|
59
|
-
// MERGE_MSG 不存在/无权限时忽略
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
res.json({ status: stdout, isMergeInProgress, mergeMessage });
|
|
63
|
-
} catch (error) {
|
|
64
|
-
res.status(500).json({ error: error.message });
|
|
65
|
-
}
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
1
|
+
// Copyright 2026 xz333221
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
import { promises as fs } from 'fs';
|
|
16
|
+
import { asyncRoute, HttpError } from '../utils/asyncRoute.js';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
|
|
19
|
+
export function registerStatusRoutes({
|
|
20
|
+
app,
|
|
21
|
+
getCommandHistory,
|
|
22
|
+
execGitCommand
|
|
23
|
+
}) {
|
|
24
|
+
// Add new endpoint for command history
|
|
25
|
+
app.get('/api/command-history', asyncRoute(async (req, res) => {
|
|
26
|
+
try {
|
|
27
|
+
const history = getCommandHistory();
|
|
28
|
+
res.json({ success: true, history });
|
|
29
|
+
} catch (error) {
|
|
30
|
+
res.status(500).json({ success: false, error: error.message });
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
app.get('/api/status_porcelain', asyncRoute(async (req, res) => {
|
|
35
|
+
try {
|
|
36
|
+
const { stdout } = await execGitCommand(['status', '--porcelain', '--untracked-files=all']);
|
|
37
|
+
// 检测是否处于 MERGING 状态(MERGE_HEAD 存在)
|
|
38
|
+
let isMergeInProgress = false;
|
|
39
|
+
let mergeMessage = '';
|
|
40
|
+
try {
|
|
41
|
+
const { stdout: mergeHead } = await execGitCommand(['rev-parse', '-q', '--verify', 'MERGE_HEAD']);
|
|
42
|
+
isMergeInProgress = mergeHead.trim().length > 0;
|
|
43
|
+
} catch (_) {
|
|
44
|
+
// MERGE_HEAD 不存在时命令会报错,属正常情况
|
|
45
|
+
isMergeInProgress = false;
|
|
46
|
+
}
|
|
47
|
+
if (isMergeInProgress) {
|
|
48
|
+
try {
|
|
49
|
+
const { stdout: gitDir } = await execGitCommand(['rev-parse', '--git-dir']);
|
|
50
|
+
const mergeMsgPath = path.resolve(gitDir.trim(), 'MERGE_MSG');
|
|
51
|
+
const raw = await fs.readFile(mergeMsgPath, 'utf-8');
|
|
52
|
+
// 过滤掉以 # 开头的注释行,拼接所有非空非注释行(保留多段信息如合并分支列表)
|
|
53
|
+
mergeMessage = raw
|
|
54
|
+
.split('\n')
|
|
55
|
+
.filter(line => line.trim() && !line.startsWith('#'))
|
|
56
|
+
.join('\n')
|
|
57
|
+
.trim();
|
|
58
|
+
} catch (_) {
|
|
59
|
+
// MERGE_MSG 不存在/无权限时忽略
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
res.json({ status: stdout, isMergeInProgress, mergeMessage });
|
|
63
|
+
} catch (error) {
|
|
64
|
+
res.status(500).json({ error: error.message });
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
}
|