zen-gitsync 2.16.24 → 2.16.27

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.
Files changed (86) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/cli/ai/platformGuard.js +200 -200
  4. package/src/cli/ai/platformGuard.test.js +253 -253
  5. package/src/gitCommit.js +484 -484
  6. package/src/ui/public/assets/AgentView-Bytr0HbV.js +4 -0
  7. package/src/ui/public/assets/AppVersionBadge-BW4vXJxH.js +2 -0
  8. package/src/ui/public/assets/BranchSelector-DsLQi1AR.js +1 -0
  9. package/src/ui/public/assets/CommitForm-CmmxW73q.js +6 -0
  10. package/src/ui/public/assets/CommonDialog-CQz6iEqp.js +1 -0
  11. package/src/ui/public/assets/EditorView-CtygNTuz.js +1 -0
  12. package/src/ui/public/assets/{FlowExecutionViewer-BLv0xSX3.js → FlowExecutionViewer-B7CdeiSp.js} +1 -1
  13. package/src/ui/public/assets/FlowOrchestrationWorkspace-DtTItIzf.js +21 -0
  14. package/src/ui/public/assets/LogList-Bo53PBwg.css +1 -0
  15. package/src/ui/public/assets/LogList-Cwem9ONv.js +7 -0
  16. package/src/ui/public/assets/MindmapView-DR5bT_oQ.js +2 -0
  17. package/src/ui/public/assets/MonitorView-DoLNabxl.js +1 -0
  18. package/src/ui/public/assets/ProjectStartupButton-BiNiH43W.js +1 -0
  19. package/src/ui/public/assets/{RemoteRepoCard-LHrI3uIa.js → RemoteRepoCard-DJ7ficOj.js} +2 -2
  20. package/src/ui/public/assets/SourceMapView-CSVCaU8d.js +3 -0
  21. package/src/ui/public/assets/{SvgIcon-BfPnov-Z.js → SvgIcon-CL2qPswh.js} +1 -1
  22. package/src/ui/public/assets/UserInputNode-BftMuqji.js +1 -0
  23. package/src/ui/public/assets/WorkbenchView-Bp2YaSGS.css +1 -0
  24. package/src/ui/public/assets/WorkbenchView-Cl9H5uXg.js +28 -0
  25. package/src/ui/public/assets/{_plugin-vue_export-helper-BpqSqjxA.js → _plugin-vue_export-helper-D3_upOKo.js} +3 -3
  26. package/src/ui/public/assets/configStore-Cqnbpz5-.js +1 -0
  27. package/src/ui/public/assets/{css.worker-Wv5dxAWO.js → css.worker-CvXBzhp8.js} +1 -1
  28. package/src/ui/public/assets/{dagre-DgwsqYn1.js → dagre-CWIGcX9d.js} +1 -1
  29. package/src/ui/public/assets/element-plus-B3pTS_5R.js +32 -0
  30. package/src/ui/public/assets/element-plus-CQrjg9us.css +1 -0
  31. package/src/ui/public/assets/{flow-mindmap-ByUzqcTH.js → flow-mindmap-B5aqOviR.js} +38 -38
  32. package/src/ui/public/assets/{html.worker-CQP8QQsS.js → html.worker-BO6WuOEO.js} +1 -1
  33. package/src/ui/public/assets/index-D89M9m30.js +71 -0
  34. package/src/ui/public/assets/{json.worker-DzV-CpCQ.js → json.worker-BkJRGcCJ.js} +1 -1
  35. package/src/ui/public/assets/{monaco-Dje8Rg13.js → monaco-BFLoT2VD.js} +198 -198
  36. package/src/ui/public/assets/socket-io-Bcae2P7B.js +1 -0
  37. package/src/ui/public/assets/toolsStore-RkALTxME.js +1 -0
  38. package/src/ui/public/assets/{ts.worker-Dth06zuC.js → ts.worker-B0J26iPs.js} +15 -15
  39. package/src/ui/public/assets/{vendor-DKiix7Qv.js → vendor-Cx8PA1NP.js} +14 -14
  40. package/src/ui/public/assets/{vue-flow-B-YyhjTY.js → vue-flow-COROsN-V.js} +2 -2
  41. package/src/ui/public/favicon.svg +75 -75
  42. package/src/ui/public/index.html +31 -30
  43. package/src/ui/public/logo.svg +74 -74
  44. package/src/ui/server/.claude/codediff.txt +8 -0
  45. package/src/ui/server/index.js +2 -1
  46. package/src/ui/server/middleware/requestLogger.js +53 -53
  47. package/src/ui/server/routes/branchStatus.js +105 -105
  48. package/src/ui/server/routes/fileOpen.js +171 -1
  49. package/src/ui/server/routes/fs.js +2 -2
  50. package/src/ui/server/routes/git/diff.js +426 -426
  51. package/src/ui/server/routes/git/diffUtils.js +149 -149
  52. package/src/ui/server/routes/git/stash.js +550 -550
  53. package/src/ui/server/routes/git/tags.js +176 -176
  54. package/src/ui/server/routes/gitOps.js +10 -0
  55. package/src/ui/server/routes/process.js +86 -86
  56. package/src/ui/server/routes/status.js +67 -67
  57. package/src/ui/server/routes/workbench/pdfText.js +145 -145
  58. package/src/ui/server/utils/createSavePortToFile.js +48 -48
  59. package/src/ui/server/utils/instanceRegistry.js +282 -282
  60. package/src/ui/server/utils/pathGuard.js +21 -0
  61. package/src/ui/server/utils/startServerOnAvailablePort.js +116 -116
  62. package/src/utils/index.js +6 -3
  63. package/src/utils/utils.test.js +89 -2
  64. package/src/ui/public/assets/AgentView-B1P7BpdL.js +0 -4
  65. package/src/ui/public/assets/AppVersionBadge-CxbNViwm.js +0 -2
  66. package/src/ui/public/assets/BranchSelector-D4dKHxxK.js +0 -1
  67. package/src/ui/public/assets/CommitForm-klcrUCW7.js +0 -6
  68. package/src/ui/public/assets/CommonDialog-DfPvpafn.js +0 -1
  69. package/src/ui/public/assets/EditorView-CZofJ-wy.js +0 -1
  70. package/src/ui/public/assets/FlowOrchestrationWorkspace-BcPCI3Cq.js +0 -21
  71. package/src/ui/public/assets/LogList-BYrHPSZw.js +0 -15
  72. package/src/ui/public/assets/LogList-CeFFytjB.css +0 -1
  73. package/src/ui/public/assets/MindmapView-CNd4Q8B8.js +0 -2
  74. package/src/ui/public/assets/MonitorView-BlmWenOX.js +0 -1
  75. package/src/ui/public/assets/ProjectStartupButton-706xOj0N.js +0 -1
  76. package/src/ui/public/assets/SourceMapView-e96cgLn7.js +0 -3
  77. package/src/ui/public/assets/UserInputNode-W1uGFT5P.js +0 -1
  78. package/src/ui/public/assets/WorkbenchView-Cfp_bLC8.js +0 -28
  79. package/src/ui/public/assets/WorkbenchView-DFO8IfcU.css +0 -1
  80. package/src/ui/public/assets/configStore-CqqnJlVS.js +0 -1
  81. package/src/ui/public/assets/element-plus--ayTjGvF.js +0 -25
  82. package/src/ui/public/assets/element-plus-D3Dn7nX0.css +0 -1
  83. package/src/ui/public/assets/index-BNymf6-p.js +0 -71
  84. package/src/ui/public/assets/socket-io-CGezBd--.js +0 -1
  85. /package/src/ui/public/assets/{editor.worker-Bd9IXS8d.js → editor.worker-Cn2oRESe.js} +0 -0
  86. /package/src/ui/public/assets/{rolldown-runtime-BM3Ffeng.js → rolldown-runtime-CMxvf4Kt.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
+ }
@@ -669,6 +669,11 @@ export function registerGitOpsRoutes({
669
669
  // 构建 git log 的 argv 数组
670
670
  const logArgs = ['log', '--all'];
671
671
 
672
+ // 分支图需要拓扑序, 保证子提交一定先于父提交出现(避免时钟偏移导致图错乱)
673
+ if (withParents) {
674
+ logArgs.push('--topo-order');
675
+ }
676
+
672
677
  // 作者筛选(支持多作者用正则 OR)
673
678
  if (author.length > 0) {
674
679
  const validAuthors = author.filter(a => a.trim() !== '');
@@ -721,6 +726,11 @@ export function registerGitOpsRoutes({
721
726
  // 构建 git log argv 数组
722
727
  const logArgs = ['log'];
723
728
 
729
+ // 分支图需要拓扑序, 保证子提交一定先于父提交出现
730
+ if (withParents) {
731
+ logArgs.push('--topo-order');
732
+ }
733
+
724
734
  // 准备分支引用,确保它们被正确识别为分支而不是文件名
725
735
  // 使用 refs/heads/ 前缀明确指示这是分支
726
736
  const formattedBranchRefs = branchRefs.split(' ')
@@ -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
+ }