codexmate 0.0.30 → 0.0.32

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 (144) hide show
  1. package/README.md +363 -421
  2. package/README.zh.md +371 -354
  3. package/cli/agents-files.js +224 -224
  4. package/cli/archive-helpers.js +446 -446
  5. package/cli/auth-profiles.js +375 -375
  6. package/cli/builtin-proxy.js +1725 -1725
  7. package/cli/claude-proxy.js +1022 -1022
  8. package/cli/config-bootstrap.js +402 -402
  9. package/cli/config-health.js +454 -454
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/local-bridge.js +324 -324
  13. package/cli/openai-bridge.js +1653 -1653
  14. package/cli/openclaw-config.js +629 -629
  15. package/cli/session-convert-args.js +69 -65
  16. package/cli/session-convert-io.js +82 -82
  17. package/cli/session-convert.js +150 -43
  18. package/cli/session-usage.concurrent.js +28 -28
  19. package/cli/session-usage.js +118 -118
  20. package/cli/session-usage.models.js +176 -176
  21. package/cli/skills.js +1141 -1141
  22. package/cli/zip-commands.js +510 -510
  23. package/cli.js +15829 -15481
  24. package/lib/automation.js +404 -404
  25. package/lib/cli-file-utils.js +151 -151
  26. package/lib/cli-models-utils.js +440 -440
  27. package/lib/cli-network-utils.js +190 -190
  28. package/lib/cli-path-utils.js +85 -85
  29. package/lib/cli-session-utils.js +121 -121
  30. package/lib/cli-sessions.js +426 -417
  31. package/lib/cli-utils.js +155 -155
  32. package/lib/cli-webhook.js +126 -126
  33. package/lib/download-artifacts.js +92 -92
  34. package/lib/mcp-stdio.js +453 -453
  35. package/lib/task-orchestrator.js +869 -869
  36. package/lib/text-diff.js +303 -303
  37. package/lib/workflow-engine.js +340 -340
  38. package/package.json +76 -76
  39. package/plugins/README.md +20 -20
  40. package/plugins/README.zh-CN.md +20 -20
  41. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  42. package/plugins/prompt-templates/computed.mjs +253 -253
  43. package/plugins/prompt-templates/index.mjs +8 -8
  44. package/plugins/prompt-templates/manifest.mjs +15 -15
  45. package/plugins/prompt-templates/methods.mjs +553 -553
  46. package/plugins/prompt-templates/overview.mjs +91 -91
  47. package/plugins/prompt-templates/ownership.mjs +19 -19
  48. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  49. package/plugins/prompt-templates/storage.mjs +64 -64
  50. package/plugins/registry.mjs +16 -16
  51. package/web-ui/app.js +647 -645
  52. package/web-ui/index.html +36 -36
  53. package/web-ui/logic.agents-diff.mjs +386 -386
  54. package/web-ui/logic.claude.mjs +168 -168
  55. package/web-ui/logic.codex.mjs +69 -69
  56. package/web-ui/logic.mjs +5 -5
  57. package/web-ui/logic.runtime.mjs +128 -128
  58. package/web-ui/logic.session-convert.mjs +70 -70
  59. package/web-ui/logic.sessions.mjs +781 -765
  60. package/web-ui/modules/api.mjs +90 -90
  61. package/web-ui/modules/app.computed.dashboard.mjs +248 -248
  62. package/web-ui/modules/app.computed.index.mjs +17 -17
  63. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  64. package/web-ui/modules/app.computed.session.mjs +693 -999
  65. package/web-ui/modules/app.constants.mjs +15 -15
  66. package/web-ui/modules/app.methods.agents.mjs +651 -632
  67. package/web-ui/modules/app.methods.claude-config.mjs +200 -200
  68. package/web-ui/modules/app.methods.codex-config.mjs +861 -917
  69. package/web-ui/modules/app.methods.index.mjs +94 -94
  70. package/web-ui/modules/app.methods.install.mjs +205 -205
  71. package/web-ui/modules/app.methods.navigation.mjs +774 -774
  72. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  73. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  74. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  75. package/web-ui/modules/app.methods.providers.mjs +529 -529
  76. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  77. package/web-ui/modules/app.methods.session-actions.mjs +591 -593
  78. package/web-ui/modules/app.methods.session-browser.mjs +1012 -984
  79. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  80. package/web-ui/modules/app.methods.session-trash.mjs +438 -438
  81. package/web-ui/modules/app.methods.startup-claude.mjs +537 -534
  82. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  83. package/web-ui/modules/app.methods.webhook.mjs +79 -79
  84. package/web-ui/modules/config-mode.computed.mjs +124 -124
  85. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  86. package/web-ui/modules/i18n.dict.mjs +3177 -3146
  87. package/web-ui/modules/i18n.mjs +62 -62
  88. package/web-ui/modules/plugins.computed.mjs +3 -3
  89. package/web-ui/modules/plugins.methods.mjs +3 -3
  90. package/web-ui/modules/plugins.storage.mjs +11 -11
  91. package/web-ui/modules/provider-url-display.mjs +17 -17
  92. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  93. package/web-ui/modules/skills.computed.mjs +107 -107
  94. package/web-ui/modules/skills.methods.mjs +482 -482
  95. package/web-ui/partials/index/layout-footer.html +13 -13
  96. package/web-ui/partials/index/layout-header.html +503 -500
  97. package/web-ui/partials/index/modal-config-template-agents.html +185 -174
  98. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  99. package/web-ui/partials/index/modal-health-check.html +45 -45
  100. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  101. package/web-ui/partials/index/modal-skills.html +200 -200
  102. package/web-ui/partials/index/modals-basic.html +162 -162
  103. package/web-ui/partials/index/panel-config-claude.html +136 -194
  104. package/web-ui/partials/index/panel-config-codex.html +197 -337
  105. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  106. package/web-ui/partials/index/panel-dashboard.html +219 -219
  107. package/web-ui/partials/index/panel-docs.html +115 -147
  108. package/web-ui/partials/index/panel-market.html +177 -177
  109. package/web-ui/partials/index/panel-orchestration.html +391 -391
  110. package/web-ui/partials/index/panel-plugins.html +253 -253
  111. package/web-ui/partials/index/panel-sessions.html +313 -308
  112. package/web-ui/partials/index/panel-settings.html +190 -190
  113. package/web-ui/partials/index/panel-trash.html +83 -88
  114. package/web-ui/partials/index/panel-usage.html +138 -371
  115. package/web-ui/res/json5.min.js +1 -1
  116. package/web-ui/res/vue.global.prod.js +13 -13
  117. package/web-ui/session-helpers.mjs +591 -594
  118. package/web-ui/source-bundle.cjs +233 -233
  119. package/web-ui/styles/base-theme.css +281 -281
  120. package/web-ui/styles/bridge-pool.css +197 -0
  121. package/web-ui/styles/controls-forms.css +433 -422
  122. package/web-ui/styles/dashboard.css +406 -406
  123. package/web-ui/styles/docs-panel.css +245 -271
  124. package/web-ui/styles/feedback.css +108 -108
  125. package/web-ui/styles/health-check-dialog.css +144 -144
  126. package/web-ui/styles/layout-shell.css +638 -626
  127. package/web-ui/styles/modals-core.css +466 -466
  128. package/web-ui/styles/navigation-panels.css +391 -391
  129. package/web-ui/styles/openclaw-structured.css +266 -266
  130. package/web-ui/styles/plugins-panel.css +564 -564
  131. package/web-ui/styles/responsive.css +392 -454
  132. package/web-ui/styles/sessions-list.css +647 -417
  133. package/web-ui/styles/sessions-preview.css +407 -407
  134. package/web-ui/styles/sessions-toolbar-trash.css +518 -334
  135. package/web-ui/styles/sessions-usage.css +588 -1040
  136. package/web-ui/styles/settings-panel.css +349 -349
  137. package/web-ui/styles/skills-list.css +305 -305
  138. package/web-ui/styles/skills-market.css +429 -429
  139. package/web-ui/styles/task-orchestration.css +822 -822
  140. package/web-ui/styles/titles-cards.css +472 -472
  141. package/web-ui/styles/trash-panel.css +90 -90
  142. package/web-ui/styles/webhook.css +81 -81
  143. package/web-ui/styles.css +24 -23
  144. package/web-ui.html +17 -17
@@ -1,556 +1,556 @@
1
- function createDefaultTaskOrchestrationState() {
2
- return {
3
- loading: false,
4
- planning: false,
5
- running: false,
6
- queueAdding: false,
7
- queueStarting: false,
8
- retrying: false,
9
- target: '',
10
- title: '',
11
- notes: '',
12
- followUpsText: '',
13
- workflowIdsText: '',
14
- selectedEngine: 'codex',
15
- runMode: 'write',
16
- concurrency: 2,
17
- autoFixRounds: 1,
18
- plan: null,
19
- planFingerprint: '',
20
- planIssues: [],
21
- planWarnings: [],
22
- overviewWarnings: [],
23
- workflows: [],
24
- queue: [],
25
- runs: [],
26
- selectedRunId: '',
27
- workspaceTab: 'queue',
28
- selectedRunDetail: null,
29
- selectedRunLoading: false,
30
- selectedRunError: '',
31
- detailRequestToken: 0,
32
- lastLoadedAt: '',
33
- lastError: ''
34
- };
35
- }
36
-
37
- function normalizeLines(text) {
38
- return String(text || '')
39
- .split(/\r?\n/g)
40
- .map((item) => item.trim())
41
- .filter(Boolean);
42
- }
43
-
44
- function normalizePositiveInteger(value, fallback, min = 1, max = 8) {
45
- const numeric = Number.parseInt(String(value), 10);
46
- if (!Number.isFinite(numeric)) {
47
- return fallback;
48
- }
49
- return Math.min(max, Math.max(min, Math.floor(numeric)));
50
- }
51
-
52
- function normalizeTaskStatusTone(status) {
53
- const normalized = String(status || '').trim().toLowerCase();
54
- if (normalized === 'success' || normalized === 'completed') return 'success';
55
- if (normalized === 'failed' || normalized === 'blocked' || normalized === 'cancelled') return 'error';
56
- if (normalized === 'running' || normalized === 'queued') return 'warn';
57
- return 'neutral';
58
- }
59
-
60
- function isActiveStatus(status) {
61
- const normalized = String(status || '').trim().toLowerCase();
62
- return normalized === 'running' || normalized === 'queued';
63
- }
64
-
65
- function normalizeTaskRunMode(value) {
66
- const normalized = String(value || '').trim().toLowerCase();
67
- if (normalized === 'read') return 'read';
68
- if (normalized === 'dry-run' || normalized === 'dryrun' || normalized === 'plan') return 'dry-run';
69
- return 'write';
70
- }
71
-
72
- function buildRunModeFlags(runMode) {
73
- const normalized = normalizeTaskRunMode(runMode);
74
- return {
75
- runMode: normalized,
76
- allowWrite: normalized === 'write',
77
- dryRun: normalized === 'dry-run'
78
- };
79
- }
80
-
81
- export function createTaskOrchestrationMethods(options = {}) {
82
- const { api } = options;
83
-
84
- return {
85
- ensureTaskOrchestrationState() {
86
- const current = this.taskOrchestration;
87
- if (current && typeof current === 'object' && !Array.isArray(current)) {
88
- const defaults = createDefaultTaskOrchestrationState();
89
- for (const [key, value] of Object.entries(defaults)) {
90
- if (typeof current[key] === 'undefined') {
91
- current[key] = value;
92
- }
93
- }
94
- current.runMode = normalizeTaskRunMode(current.runMode);
95
- return current;
96
- }
97
- this.taskOrchestration = createDefaultTaskOrchestrationState();
98
- return this.taskOrchestration;
99
- },
100
-
101
- buildTaskOrchestrationRequest() {
102
- const state = this.ensureTaskOrchestrationState();
103
- const flags = buildRunModeFlags(state.runMode);
104
- return {
105
- title: String(state.title || '').trim(),
106
- target: String(state.target || '').trim(),
107
- notes: String(state.notes || '').trim(),
108
- followUps: normalizeLines(state.followUpsText),
109
- workflowIds: normalizeLines(state.workflowIdsText),
110
- engine: String(state.selectedEngine || 'codex').trim().toLowerCase() === 'workflow' ? 'workflow' : 'codex',
111
- allowWrite: flags.allowWrite,
112
- dryRun: flags.dryRun,
113
- concurrency: normalizePositiveInteger(state.concurrency, 2, 1, 8),
114
- autoFixRounds: normalizePositiveInteger(state.autoFixRounds, 1, 0, 5)
115
- };
116
- },
117
-
118
- buildTaskOrchestrationFingerprint() {
119
- const req = this.buildTaskOrchestrationRequest();
120
- return JSON.stringify({
121
- title: req.title,
122
- target: req.target,
123
- notes: req.notes,
124
- followUps: req.followUps,
125
- workflowIds: req.workflowIds,
126
- engine: req.engine,
127
- allowWrite: req.allowWrite,
128
- dryRun: req.dryRun,
129
- concurrency: req.concurrency,
130
- autoFixRounds: req.autoFixRounds
131
- });
132
- },
133
-
134
- taskRunStatusTone(status) {
135
- return normalizeTaskStatusTone(status);
136
- },
137
-
138
- isTaskRunActive(status) {
139
- return isActiveStatus(status);
140
- },
141
-
142
- formatTaskNodeDependencies(node) {
143
- const dependsOn = Array.isArray(node && node.dependsOn) ? node.dependsOn : [];
144
- return dependsOn.length > 0 ? dependsOn.join(', ') : '无';
145
- },
146
-
147
- formatTaskNodeLogs(logs) {
148
- if (!Array.isArray(logs) || logs.length === 0) {
149
- return '(no logs)';
150
- }
151
- return logs.map((item) => `${item && item.at ? item.at : ''} ${item && item.level ? item.level : ''} ${item && item.message ? item.message : ''}`.trim()).join('\n');
152
- },
153
-
154
- appendTaskWorkflowId(workflowId) {
155
- const state = this.ensureTaskOrchestrationState();
156
- const normalizedWorkflowId = typeof workflowId === 'string' ? workflowId.trim() : '';
157
- if (!normalizedWorkflowId) {
158
- return;
159
- }
160
- const nextWorkflowIds = normalizeLines(state.workflowIdsText);
161
- if (!nextWorkflowIds.includes(normalizedWorkflowId)) {
162
- nextWorkflowIds.push(normalizedWorkflowId);
163
- }
164
- state.selectedEngine = 'workflow';
165
- state.workflowIdsText = nextWorkflowIds.join('\n');
166
- },
167
-
168
- async loadTaskOrchestrationOverview(options = {}) {
169
- const state = this.ensureTaskOrchestrationState();
170
- if (state.loading && !options.forceRefresh) {
171
- return null;
172
- }
173
- const silent = !!options.silent;
174
- state.loading = true;
175
- state.lastError = '';
176
- try {
177
- const res = await api('task-overview', {
178
- queueLimit: 20,
179
- runLimit: 20
180
- });
181
- if (res && res.error) {
182
- state.lastError = res.error;
183
- if (!silent) {
184
- this.showMessage(res.error, 'error');
185
- }
186
- return res;
187
- }
188
- state.workflows = Array.isArray(res && res.workflows) ? res.workflows : [];
189
- state.queue = Array.isArray(res && res.queue) ? res.queue : [];
190
- state.runs = Array.isArray(res && res.runs) ? res.runs : [];
191
- state.overviewWarnings = Array.isArray(res && res.warnings) ? res.warnings : [];
192
- state.lastLoadedAt = new Date().toISOString();
193
- if (!state.selectedRunId && state.runs.length > 0) {
194
- state.selectedRunId = state.runs[0].runId || '';
195
- }
196
- const shouldRefreshSelectedDetail = !!state.selectedRunId
197
- && (options.includeDetail !== false
198
- || (state.selectedRunDetail && this.isTaskRunActive(state.selectedRunDetail && state.selectedRunDetail.run && state.selectedRunDetail.run.status)));
199
- if (shouldRefreshSelectedDetail) {
200
- await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
201
- }
202
- this.syncTaskOrchestrationPolling();
203
- return res;
204
- } catch (error) {
205
- const message = error && error.message ? error.message : '任务编排概览加载失败';
206
- state.lastError = message;
207
- if (!silent) {
208
- this.showMessage(message, 'error');
209
- }
210
- return { error: message };
211
- } finally {
212
- state.loading = false;
213
- }
214
- },
215
-
216
- async previewTaskPlan(options = {}) {
217
- const state = this.ensureTaskOrchestrationState();
218
- if (state.planning) {
219
- return null;
220
- }
221
- state.planning = true;
222
- try {
223
- const res = await api('task-plan', this.buildTaskOrchestrationRequest());
224
- state.plan = res && res.plan ? res.plan : null;
225
- state.planIssues = Array.isArray(res && res.issues) ? res.issues : [];
226
- state.planWarnings = Array.isArray(res && res.warnings) ? res.warnings : [];
227
- state.planFingerprint = state.plan ? this.buildTaskOrchestrationFingerprint() : '';
228
- if (res && res.error) {
229
- if (!options.silent) {
230
- this.showMessage(res.error, 'error');
231
- }
232
- return res;
233
- }
234
- if (!options.silent) {
235
- this.showMessage('任务计划已更新', 'success');
236
- }
237
- return res;
238
- } catch (error) {
239
- const message = error && error.message ? error.message : '任务计划生成失败';
240
- state.plan = null;
241
- state.planIssues = [];
242
- state.planWarnings = [];
243
- if (!options.silent) {
244
- this.showMessage(message, 'error');
245
- }
246
- return { error: message };
247
- } finally {
248
- state.planning = false;
249
- }
250
- },
251
-
252
- async runTaskOrchestration() {
253
- const state = this.ensureTaskOrchestrationState();
254
- if (state.running) {
255
- return null;
256
- }
257
- state.running = true;
258
- try {
259
- const res = await api('task-run', {
260
- ...this.buildTaskOrchestrationRequest(),
261
- detach: true
262
- });
263
- if (res && res.error) {
264
- this.showMessage(res.error, 'error');
265
- return res;
266
- }
267
- state.selectedRunId = res.runId || state.selectedRunId;
268
- await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
269
- if (state.selectedRunId) {
270
- await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
271
- }
272
- this.syncTaskOrchestrationPolling();
273
- this.showMessage(`任务已启动: ${res.runId || res.taskId || 'unknown'}`, 'success');
274
- return res;
275
- } catch (error) {
276
- const message = error && error.message ? error.message : '任务启动失败';
277
- this.showMessage(message, 'error');
278
- return { error: message };
279
- } finally {
280
- state.running = false;
281
- }
282
- },
283
-
284
- async addTaskOrchestrationToQueue(options = {}) {
285
- const state = this.ensureTaskOrchestrationState();
286
- if (state.queueAdding) {
287
- return null;
288
- }
289
- state.queueAdding = true;
290
- try {
291
- const res = await api('task-queue-add', this.buildTaskOrchestrationRequest());
292
- if (res && res.error) {
293
- if (!options.silent) {
294
- this.showMessage(res.error, 'error');
295
- }
296
- return res;
297
- }
298
- if (!options.deferRefresh) {
299
- await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
300
- }
301
- if (!options.silent) {
302
- this.showMessage(`已加入队列: ${res && res.task ? res.task.taskId : ''}`.trim(), 'success');
303
- }
304
- return res;
305
- } catch (error) {
306
- const message = error && error.message ? error.message : '加入队列失败';
307
- if (!options.silent) {
308
- this.showMessage(message, 'error');
309
- }
310
- return { error: message };
311
- } finally {
312
- state.queueAdding = false;
313
- }
314
- },
315
-
316
- async planAndRunTaskOrchestration() {
317
- const state = this.ensureTaskOrchestrationState();
318
- if (state.running || state.planning) {
319
- return null;
320
- }
321
- if (!String(state.target || '').trim()) {
322
- return null;
323
- }
324
- if (buildRunModeFlags(state.runMode).dryRun) {
325
- return this.previewTaskPlan({ silent: false });
326
- }
327
- const fingerprint = this.buildTaskOrchestrationFingerprint();
328
- const shouldPreview = !state.plan || state.planFingerprint !== fingerprint;
329
- if (shouldPreview) {
330
- const preview = await this.previewTaskPlan({ silent: true });
331
- if (preview && preview.error) {
332
- this.showMessage(preview.error, 'error');
333
- return preview;
334
- }
335
- }
336
- if (state.planIssues && state.planIssues.length) {
337
- this.showMessage('计划存在问题,请先修复再执行', 'error');
338
- return { error: 'Plan has blocking issues' };
339
- }
340
- return this.runTaskOrchestration();
341
- },
342
-
343
- async queueTaskOrchestrationAndStart() {
344
- const state = this.ensureTaskOrchestrationState();
345
- if (state.queueAdding || state.queueStarting || state.planning || state.running) {
346
- return null;
347
- }
348
- if (!String(state.target || '').trim()) {
349
- return null;
350
- }
351
- const queued = await this.addTaskOrchestrationToQueue({ silent: true, deferRefresh: true });
352
- if (queued && queued.error) {
353
- this.showMessage(queued.error, 'error');
354
- return queued;
355
- }
356
- return this.startTaskQueueRunner();
357
- },
358
-
359
- async startTaskQueueRunner() {
360
- const state = this.ensureTaskOrchestrationState();
361
- if (state.queueStarting) {
362
- return null;
363
- }
364
- state.queueStarting = true;
365
- try {
366
- const res = await api('task-queue-start', { detach: true });
367
- if (res && res.error) {
368
- this.showMessage(res.error, 'error');
369
- return res;
370
- }
371
- await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
372
- this.syncTaskOrchestrationPolling();
373
- this.showMessage(res && res.alreadyRunning ? '队列执行器已在运行' : '队列执行器已启动', 'success');
374
- return res;
375
- } catch (error) {
376
- const message = error && error.message ? error.message : '启动队列失败';
377
- this.showMessage(message, 'error');
378
- return { error: message };
379
- } finally {
380
- state.queueStarting = false;
381
- }
382
- },
383
-
384
- async loadTaskRunDetail(runId, options = {}) {
385
- const state = this.ensureTaskOrchestrationState();
386
- const normalizedRunId = String(runId || '').trim();
387
- if (!normalizedRunId) {
388
- state.selectedRunDetail = null;
389
- state.selectedRunId = '';
390
- state.selectedRunError = '';
391
- this.syncTaskOrchestrationPolling();
392
- return null;
393
- }
394
- const requestToken = (state.detailRequestToken || 0) + 1;
395
- const previousRunId = state.selectedRunId;
396
- state.detailRequestToken = requestToken;
397
- state.selectedRunLoading = true;
398
- state.selectedRunId = normalizedRunId;
399
- if (options.switchToDetail === true || !options.silent) {
400
- state.workspaceTab = 'detail';
401
- }
402
- state.selectedRunError = '';
403
- if (previousRunId !== normalizedRunId) {
404
- state.selectedRunDetail = null;
405
- }
406
- try {
407
- const res = await api('task-run-detail', { runId: normalizedRunId });
408
- if (state.detailRequestToken !== requestToken) {
409
- return res;
410
- }
411
- if (res && res.error) {
412
- state.selectedRunDetail = null;
413
- state.selectedRunError = res.error;
414
- if (!options.silent) {
415
- this.showMessage(res.error, 'error');
416
- }
417
- return res;
418
- }
419
- state.selectedRunDetail = res;
420
- state.selectedRunError = '';
421
- this.syncTaskOrchestrationPolling();
422
- return res;
423
- } catch (error) {
424
- const message = error && error.message ? error.message : '加载任务详情失败';
425
- if (state.detailRequestToken === requestToken) {
426
- state.selectedRunDetail = null;
427
- state.selectedRunError = message;
428
- }
429
- if (!options.silent) {
430
- this.showMessage(message, 'error');
431
- }
432
- return { error: message };
433
- } finally {
434
- if (state.detailRequestToken === requestToken) {
435
- state.selectedRunLoading = false;
436
- }
437
- }
438
- },
439
-
440
- async selectTaskRun(runId) {
441
- return this.loadTaskRunDetail(runId, { silent: false, switchToDetail: true });
442
- },
443
-
444
- async retryTaskRunFromUi(runId) {
445
- const state = this.ensureTaskOrchestrationState();
446
- const normalizedRunId = String(runId || '').trim();
447
- if (!normalizedRunId || state.retrying) {
448
- return null;
449
- }
450
- state.retrying = true;
451
- try {
452
- const res = await api('task-retry', { runId: normalizedRunId, detach: true });
453
- if (res && res.error) {
454
- this.showMessage(res.error, 'error');
455
- return res;
456
- }
457
- state.selectedRunId = res.runId || state.selectedRunId;
458
- await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
459
- if (state.selectedRunId) {
460
- await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
461
- }
462
- this.syncTaskOrchestrationPolling();
463
- this.showMessage(`已开始重试: ${res.runId || normalizedRunId}`, 'success');
464
- return res;
465
- } catch (error) {
466
- const message = error && error.message ? error.message : '重试任务失败';
467
- this.showMessage(message, 'error');
468
- return { error: message };
469
- } finally {
470
- state.retrying = false;
471
- }
472
- },
473
-
474
- async cancelTaskRunFromUi(target) {
475
- const normalizedTarget = String(target || '').trim();
476
- if (!normalizedTarget) {
477
- return null;
478
- }
479
- try {
480
- const res = await api('task-cancel', { target: normalizedTarget });
481
- if (res && res.error) {
482
- this.showMessage(res.error, 'error');
483
- return res;
484
- }
485
- await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
486
- if (this.taskOrchestration.selectedRunId) {
487
- await this.loadTaskRunDetail(this.taskOrchestration.selectedRunId, { silent: true });
488
- }
489
- this.syncTaskOrchestrationPolling();
490
- this.showMessage('已发出取消请求', 'success');
491
- return res;
492
- } catch (error) {
493
- const message = error && error.message ? error.message : '取消任务失败';
494
- this.showMessage(message, 'error');
495
- return { error: message };
496
- }
497
- },
498
-
499
- taskOrchestrationHasLiveActivity() {
500
- const state = this.ensureTaskOrchestrationState();
501
- const queue = Array.isArray(state.queue) ? state.queue : [];
502
- if (queue.some((item) => isActiveStatus(item && (item.status || item.runStatus)))) {
503
- return true;
504
- }
505
- const detail = state.selectedRunDetail;
506
- const selectedStatus = detail && detail.run ? detail.run.status : '';
507
- if (isActiveStatus(selectedStatus)) {
508
- return true;
509
- }
510
- const runs = Array.isArray(state.runs) ? state.runs : [];
511
- return runs.some((item) => isActiveStatus(item && item.status));
512
- },
513
-
514
- stopTaskOrchestrationPolling() {
515
- if (this._taskOrchestrationPollTimer) {
516
- clearTimeout(this._taskOrchestrationPollTimer);
517
- this._taskOrchestrationPollTimer = 0;
518
- }
519
- },
520
-
521
- syncTaskOrchestrationPolling() {
522
- this.stopTaskOrchestrationPolling();
523
- if (this.mainTab !== 'orchestration') {
524
- return;
525
- }
526
- if (!this.taskOrchestrationHasLiveActivity()) {
527
- return;
528
- }
529
- this._taskOrchestrationPollTimer = setTimeout(async () => {
530
- this._taskOrchestrationPollTimer = 0;
531
- if (this.mainTab !== 'orchestration') {
532
- return;
533
- }
534
- await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: true });
535
- }, 4000);
536
- },
537
-
538
- resetTaskOrchestrationDraft() {
539
- const state = this.ensureTaskOrchestrationState();
540
- state.target = '';
541
- state.title = '';
542
- state.notes = '';
543
- state.followUpsText = '';
544
- state.workflowIdsText = '';
545
- state.selectedEngine = 'codex';
546
- state.runMode = 'write';
547
- state.concurrency = 2;
548
- state.autoFixRounds = 1;
549
- state.plan = null;
550
- state.planIssues = [];
551
- state.planWarnings = [];
552
- state.lastError = '';
553
- this.syncTaskOrchestrationPolling();
554
- }
555
- };
556
- }
1
+ function createDefaultTaskOrchestrationState() {
2
+ return {
3
+ loading: false,
4
+ planning: false,
5
+ running: false,
6
+ queueAdding: false,
7
+ queueStarting: false,
8
+ retrying: false,
9
+ target: '',
10
+ title: '',
11
+ notes: '',
12
+ followUpsText: '',
13
+ workflowIdsText: '',
14
+ selectedEngine: 'codex',
15
+ runMode: 'write',
16
+ concurrency: 2,
17
+ autoFixRounds: 1,
18
+ plan: null,
19
+ planFingerprint: '',
20
+ planIssues: [],
21
+ planWarnings: [],
22
+ overviewWarnings: [],
23
+ workflows: [],
24
+ queue: [],
25
+ runs: [],
26
+ selectedRunId: '',
27
+ workspaceTab: 'queue',
28
+ selectedRunDetail: null,
29
+ selectedRunLoading: false,
30
+ selectedRunError: '',
31
+ detailRequestToken: 0,
32
+ lastLoadedAt: '',
33
+ lastError: ''
34
+ };
35
+ }
36
+
37
+ function normalizeLines(text) {
38
+ return String(text || '')
39
+ .split(/\r?\n/g)
40
+ .map((item) => item.trim())
41
+ .filter(Boolean);
42
+ }
43
+
44
+ function normalizePositiveInteger(value, fallback, min = 1, max = 8) {
45
+ const numeric = Number.parseInt(String(value), 10);
46
+ if (!Number.isFinite(numeric)) {
47
+ return fallback;
48
+ }
49
+ return Math.min(max, Math.max(min, Math.floor(numeric)));
50
+ }
51
+
52
+ function normalizeTaskStatusTone(status) {
53
+ const normalized = String(status || '').trim().toLowerCase();
54
+ if (normalized === 'success' || normalized === 'completed') return 'success';
55
+ if (normalized === 'failed' || normalized === 'blocked' || normalized === 'cancelled') return 'error';
56
+ if (normalized === 'running' || normalized === 'queued') return 'warn';
57
+ return 'neutral';
58
+ }
59
+
60
+ function isActiveStatus(status) {
61
+ const normalized = String(status || '').trim().toLowerCase();
62
+ return normalized === 'running' || normalized === 'queued';
63
+ }
64
+
65
+ function normalizeTaskRunMode(value) {
66
+ const normalized = String(value || '').trim().toLowerCase();
67
+ if (normalized === 'read') return 'read';
68
+ if (normalized === 'dry-run' || normalized === 'dryrun' || normalized === 'plan') return 'dry-run';
69
+ return 'write';
70
+ }
71
+
72
+ function buildRunModeFlags(runMode) {
73
+ const normalized = normalizeTaskRunMode(runMode);
74
+ return {
75
+ runMode: normalized,
76
+ allowWrite: normalized === 'write',
77
+ dryRun: normalized === 'dry-run'
78
+ };
79
+ }
80
+
81
+ export function createTaskOrchestrationMethods(options = {}) {
82
+ const { api } = options;
83
+
84
+ return {
85
+ ensureTaskOrchestrationState() {
86
+ const current = this.taskOrchestration;
87
+ if (current && typeof current === 'object' && !Array.isArray(current)) {
88
+ const defaults = createDefaultTaskOrchestrationState();
89
+ for (const [key, value] of Object.entries(defaults)) {
90
+ if (typeof current[key] === 'undefined') {
91
+ current[key] = value;
92
+ }
93
+ }
94
+ current.runMode = normalizeTaskRunMode(current.runMode);
95
+ return current;
96
+ }
97
+ this.taskOrchestration = createDefaultTaskOrchestrationState();
98
+ return this.taskOrchestration;
99
+ },
100
+
101
+ buildTaskOrchestrationRequest() {
102
+ const state = this.ensureTaskOrchestrationState();
103
+ const flags = buildRunModeFlags(state.runMode);
104
+ return {
105
+ title: String(state.title || '').trim(),
106
+ target: String(state.target || '').trim(),
107
+ notes: String(state.notes || '').trim(),
108
+ followUps: normalizeLines(state.followUpsText),
109
+ workflowIds: normalizeLines(state.workflowIdsText),
110
+ engine: String(state.selectedEngine || 'codex').trim().toLowerCase() === 'workflow' ? 'workflow' : 'codex',
111
+ allowWrite: flags.allowWrite,
112
+ dryRun: flags.dryRun,
113
+ concurrency: normalizePositiveInteger(state.concurrency, 2, 1, 8),
114
+ autoFixRounds: normalizePositiveInteger(state.autoFixRounds, 1, 0, 5)
115
+ };
116
+ },
117
+
118
+ buildTaskOrchestrationFingerprint() {
119
+ const req = this.buildTaskOrchestrationRequest();
120
+ return JSON.stringify({
121
+ title: req.title,
122
+ target: req.target,
123
+ notes: req.notes,
124
+ followUps: req.followUps,
125
+ workflowIds: req.workflowIds,
126
+ engine: req.engine,
127
+ allowWrite: req.allowWrite,
128
+ dryRun: req.dryRun,
129
+ concurrency: req.concurrency,
130
+ autoFixRounds: req.autoFixRounds
131
+ });
132
+ },
133
+
134
+ taskRunStatusTone(status) {
135
+ return normalizeTaskStatusTone(status);
136
+ },
137
+
138
+ isTaskRunActive(status) {
139
+ return isActiveStatus(status);
140
+ },
141
+
142
+ formatTaskNodeDependencies(node) {
143
+ const dependsOn = Array.isArray(node && node.dependsOn) ? node.dependsOn : [];
144
+ return dependsOn.length > 0 ? dependsOn.join(', ') : '无';
145
+ },
146
+
147
+ formatTaskNodeLogs(logs) {
148
+ if (!Array.isArray(logs) || logs.length === 0) {
149
+ return '(no logs)';
150
+ }
151
+ return logs.map((item) => `${item && item.at ? item.at : ''} ${item && item.level ? item.level : ''} ${item && item.message ? item.message : ''}`.trim()).join('\n');
152
+ },
153
+
154
+ appendTaskWorkflowId(workflowId) {
155
+ const state = this.ensureTaskOrchestrationState();
156
+ const normalizedWorkflowId = typeof workflowId === 'string' ? workflowId.trim() : '';
157
+ if (!normalizedWorkflowId) {
158
+ return;
159
+ }
160
+ const nextWorkflowIds = normalizeLines(state.workflowIdsText);
161
+ if (!nextWorkflowIds.includes(normalizedWorkflowId)) {
162
+ nextWorkflowIds.push(normalizedWorkflowId);
163
+ }
164
+ state.selectedEngine = 'workflow';
165
+ state.workflowIdsText = nextWorkflowIds.join('\n');
166
+ },
167
+
168
+ async loadTaskOrchestrationOverview(options = {}) {
169
+ const state = this.ensureTaskOrchestrationState();
170
+ if (state.loading && !options.forceRefresh) {
171
+ return null;
172
+ }
173
+ const silent = !!options.silent;
174
+ state.loading = true;
175
+ state.lastError = '';
176
+ try {
177
+ const res = await api('task-overview', {
178
+ queueLimit: 20,
179
+ runLimit: 20
180
+ });
181
+ if (res && res.error) {
182
+ state.lastError = res.error;
183
+ if (!silent) {
184
+ this.showMessage(res.error, 'error');
185
+ }
186
+ return res;
187
+ }
188
+ state.workflows = Array.isArray(res && res.workflows) ? res.workflows : [];
189
+ state.queue = Array.isArray(res && res.queue) ? res.queue : [];
190
+ state.runs = Array.isArray(res && res.runs) ? res.runs : [];
191
+ state.overviewWarnings = Array.isArray(res && res.warnings) ? res.warnings : [];
192
+ state.lastLoadedAt = new Date().toISOString();
193
+ if (!state.selectedRunId && state.runs.length > 0) {
194
+ state.selectedRunId = state.runs[0].runId || '';
195
+ }
196
+ const shouldRefreshSelectedDetail = !!state.selectedRunId
197
+ && (options.includeDetail !== false
198
+ || (state.selectedRunDetail && this.isTaskRunActive(state.selectedRunDetail && state.selectedRunDetail.run && state.selectedRunDetail.run.status)));
199
+ if (shouldRefreshSelectedDetail) {
200
+ await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
201
+ }
202
+ this.syncTaskOrchestrationPolling();
203
+ return res;
204
+ } catch (error) {
205
+ const message = error && error.message ? error.message : '任务编排概览加载失败';
206
+ state.lastError = message;
207
+ if (!silent) {
208
+ this.showMessage(message, 'error');
209
+ }
210
+ return { error: message };
211
+ } finally {
212
+ state.loading = false;
213
+ }
214
+ },
215
+
216
+ async previewTaskPlan(options = {}) {
217
+ const state = this.ensureTaskOrchestrationState();
218
+ if (state.planning) {
219
+ return null;
220
+ }
221
+ state.planning = true;
222
+ try {
223
+ const res = await api('task-plan', this.buildTaskOrchestrationRequest());
224
+ state.plan = res && res.plan ? res.plan : null;
225
+ state.planIssues = Array.isArray(res && res.issues) ? res.issues : [];
226
+ state.planWarnings = Array.isArray(res && res.warnings) ? res.warnings : [];
227
+ state.planFingerprint = state.plan ? this.buildTaskOrchestrationFingerprint() : '';
228
+ if (res && res.error) {
229
+ if (!options.silent) {
230
+ this.showMessage(res.error, 'error');
231
+ }
232
+ return res;
233
+ }
234
+ if (!options.silent) {
235
+ this.showMessage('任务计划已更新', 'success');
236
+ }
237
+ return res;
238
+ } catch (error) {
239
+ const message = error && error.message ? error.message : '任务计划生成失败';
240
+ state.plan = null;
241
+ state.planIssues = [];
242
+ state.planWarnings = [];
243
+ if (!options.silent) {
244
+ this.showMessage(message, 'error');
245
+ }
246
+ return { error: message };
247
+ } finally {
248
+ state.planning = false;
249
+ }
250
+ },
251
+
252
+ async runTaskOrchestration() {
253
+ const state = this.ensureTaskOrchestrationState();
254
+ if (state.running) {
255
+ return null;
256
+ }
257
+ state.running = true;
258
+ try {
259
+ const res = await api('task-run', {
260
+ ...this.buildTaskOrchestrationRequest(),
261
+ detach: true
262
+ });
263
+ if (res && res.error) {
264
+ this.showMessage(res.error, 'error');
265
+ return res;
266
+ }
267
+ state.selectedRunId = res.runId || state.selectedRunId;
268
+ await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
269
+ if (state.selectedRunId) {
270
+ await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
271
+ }
272
+ this.syncTaskOrchestrationPolling();
273
+ this.showMessage(`任务已启动: ${res.runId || res.taskId || 'unknown'}`, 'success');
274
+ return res;
275
+ } catch (error) {
276
+ const message = error && error.message ? error.message : '任务启动失败';
277
+ this.showMessage(message, 'error');
278
+ return { error: message };
279
+ } finally {
280
+ state.running = false;
281
+ }
282
+ },
283
+
284
+ async addTaskOrchestrationToQueue(options = {}) {
285
+ const state = this.ensureTaskOrchestrationState();
286
+ if (state.queueAdding) {
287
+ return null;
288
+ }
289
+ state.queueAdding = true;
290
+ try {
291
+ const res = await api('task-queue-add', this.buildTaskOrchestrationRequest());
292
+ if (res && res.error) {
293
+ if (!options.silent) {
294
+ this.showMessage(res.error, 'error');
295
+ }
296
+ return res;
297
+ }
298
+ if (!options.deferRefresh) {
299
+ await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
300
+ }
301
+ if (!options.silent) {
302
+ this.showMessage(`已加入队列: ${res && res.task ? res.task.taskId : ''}`.trim(), 'success');
303
+ }
304
+ return res;
305
+ } catch (error) {
306
+ const message = error && error.message ? error.message : '加入队列失败';
307
+ if (!options.silent) {
308
+ this.showMessage(message, 'error');
309
+ }
310
+ return { error: message };
311
+ } finally {
312
+ state.queueAdding = false;
313
+ }
314
+ },
315
+
316
+ async planAndRunTaskOrchestration() {
317
+ const state = this.ensureTaskOrchestrationState();
318
+ if (state.running || state.planning) {
319
+ return null;
320
+ }
321
+ if (!String(state.target || '').trim()) {
322
+ return null;
323
+ }
324
+ if (buildRunModeFlags(state.runMode).dryRun) {
325
+ return this.previewTaskPlan({ silent: false });
326
+ }
327
+ const fingerprint = this.buildTaskOrchestrationFingerprint();
328
+ const shouldPreview = !state.plan || state.planFingerprint !== fingerprint;
329
+ if (shouldPreview) {
330
+ const preview = await this.previewTaskPlan({ silent: true });
331
+ if (preview && preview.error) {
332
+ this.showMessage(preview.error, 'error');
333
+ return preview;
334
+ }
335
+ }
336
+ if (state.planIssues && state.planIssues.length) {
337
+ this.showMessage('计划存在问题,请先修复再执行', 'error');
338
+ return { error: 'Plan has blocking issues' };
339
+ }
340
+ return this.runTaskOrchestration();
341
+ },
342
+
343
+ async queueTaskOrchestrationAndStart() {
344
+ const state = this.ensureTaskOrchestrationState();
345
+ if (state.queueAdding || state.queueStarting || state.planning || state.running) {
346
+ return null;
347
+ }
348
+ if (!String(state.target || '').trim()) {
349
+ return null;
350
+ }
351
+ const queued = await this.addTaskOrchestrationToQueue({ silent: true, deferRefresh: true });
352
+ if (queued && queued.error) {
353
+ this.showMessage(queued.error, 'error');
354
+ return queued;
355
+ }
356
+ return this.startTaskQueueRunner();
357
+ },
358
+
359
+ async startTaskQueueRunner() {
360
+ const state = this.ensureTaskOrchestrationState();
361
+ if (state.queueStarting) {
362
+ return null;
363
+ }
364
+ state.queueStarting = true;
365
+ try {
366
+ const res = await api('task-queue-start', { detach: true });
367
+ if (res && res.error) {
368
+ this.showMessage(res.error, 'error');
369
+ return res;
370
+ }
371
+ await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
372
+ this.syncTaskOrchestrationPolling();
373
+ this.showMessage(res && res.alreadyRunning ? '队列执行器已在运行' : '队列执行器已启动', 'success');
374
+ return res;
375
+ } catch (error) {
376
+ const message = error && error.message ? error.message : '启动队列失败';
377
+ this.showMessage(message, 'error');
378
+ return { error: message };
379
+ } finally {
380
+ state.queueStarting = false;
381
+ }
382
+ },
383
+
384
+ async loadTaskRunDetail(runId, options = {}) {
385
+ const state = this.ensureTaskOrchestrationState();
386
+ const normalizedRunId = String(runId || '').trim();
387
+ if (!normalizedRunId) {
388
+ state.selectedRunDetail = null;
389
+ state.selectedRunId = '';
390
+ state.selectedRunError = '';
391
+ this.syncTaskOrchestrationPolling();
392
+ return null;
393
+ }
394
+ const requestToken = (state.detailRequestToken || 0) + 1;
395
+ const previousRunId = state.selectedRunId;
396
+ state.detailRequestToken = requestToken;
397
+ state.selectedRunLoading = true;
398
+ state.selectedRunId = normalizedRunId;
399
+ if (options.switchToDetail === true || !options.silent) {
400
+ state.workspaceTab = 'detail';
401
+ }
402
+ state.selectedRunError = '';
403
+ if (previousRunId !== normalizedRunId) {
404
+ state.selectedRunDetail = null;
405
+ }
406
+ try {
407
+ const res = await api('task-run-detail', { runId: normalizedRunId });
408
+ if (state.detailRequestToken !== requestToken) {
409
+ return res;
410
+ }
411
+ if (res && res.error) {
412
+ state.selectedRunDetail = null;
413
+ state.selectedRunError = res.error;
414
+ if (!options.silent) {
415
+ this.showMessage(res.error, 'error');
416
+ }
417
+ return res;
418
+ }
419
+ state.selectedRunDetail = res;
420
+ state.selectedRunError = '';
421
+ this.syncTaskOrchestrationPolling();
422
+ return res;
423
+ } catch (error) {
424
+ const message = error && error.message ? error.message : '加载任务详情失败';
425
+ if (state.detailRequestToken === requestToken) {
426
+ state.selectedRunDetail = null;
427
+ state.selectedRunError = message;
428
+ }
429
+ if (!options.silent) {
430
+ this.showMessage(message, 'error');
431
+ }
432
+ return { error: message };
433
+ } finally {
434
+ if (state.detailRequestToken === requestToken) {
435
+ state.selectedRunLoading = false;
436
+ }
437
+ }
438
+ },
439
+
440
+ async selectTaskRun(runId) {
441
+ return this.loadTaskRunDetail(runId, { silent: false, switchToDetail: true });
442
+ },
443
+
444
+ async retryTaskRunFromUi(runId) {
445
+ const state = this.ensureTaskOrchestrationState();
446
+ const normalizedRunId = String(runId || '').trim();
447
+ if (!normalizedRunId || state.retrying) {
448
+ return null;
449
+ }
450
+ state.retrying = true;
451
+ try {
452
+ const res = await api('task-retry', { runId: normalizedRunId, detach: true });
453
+ if (res && res.error) {
454
+ this.showMessage(res.error, 'error');
455
+ return res;
456
+ }
457
+ state.selectedRunId = res.runId || state.selectedRunId;
458
+ await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
459
+ if (state.selectedRunId) {
460
+ await this.loadTaskRunDetail(state.selectedRunId, { silent: true });
461
+ }
462
+ this.syncTaskOrchestrationPolling();
463
+ this.showMessage(`已开始重试: ${res.runId || normalizedRunId}`, 'success');
464
+ return res;
465
+ } catch (error) {
466
+ const message = error && error.message ? error.message : '重试任务失败';
467
+ this.showMessage(message, 'error');
468
+ return { error: message };
469
+ } finally {
470
+ state.retrying = false;
471
+ }
472
+ },
473
+
474
+ async cancelTaskRunFromUi(target) {
475
+ const normalizedTarget = String(target || '').trim();
476
+ if (!normalizedTarget) {
477
+ return null;
478
+ }
479
+ try {
480
+ const res = await api('task-cancel', { target: normalizedTarget });
481
+ if (res && res.error) {
482
+ this.showMessage(res.error, 'error');
483
+ return res;
484
+ }
485
+ await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: false });
486
+ if (this.taskOrchestration.selectedRunId) {
487
+ await this.loadTaskRunDetail(this.taskOrchestration.selectedRunId, { silent: true });
488
+ }
489
+ this.syncTaskOrchestrationPolling();
490
+ this.showMessage('已发出取消请求', 'success');
491
+ return res;
492
+ } catch (error) {
493
+ const message = error && error.message ? error.message : '取消任务失败';
494
+ this.showMessage(message, 'error');
495
+ return { error: message };
496
+ }
497
+ },
498
+
499
+ taskOrchestrationHasLiveActivity() {
500
+ const state = this.ensureTaskOrchestrationState();
501
+ const queue = Array.isArray(state.queue) ? state.queue : [];
502
+ if (queue.some((item) => isActiveStatus(item && (item.status || item.runStatus)))) {
503
+ return true;
504
+ }
505
+ const detail = state.selectedRunDetail;
506
+ const selectedStatus = detail && detail.run ? detail.run.status : '';
507
+ if (isActiveStatus(selectedStatus)) {
508
+ return true;
509
+ }
510
+ const runs = Array.isArray(state.runs) ? state.runs : [];
511
+ return runs.some((item) => isActiveStatus(item && item.status));
512
+ },
513
+
514
+ stopTaskOrchestrationPolling() {
515
+ if (this._taskOrchestrationPollTimer) {
516
+ clearTimeout(this._taskOrchestrationPollTimer);
517
+ this._taskOrchestrationPollTimer = 0;
518
+ }
519
+ },
520
+
521
+ syncTaskOrchestrationPolling() {
522
+ this.stopTaskOrchestrationPolling();
523
+ if (this.mainTab !== 'orchestration') {
524
+ return;
525
+ }
526
+ if (!this.taskOrchestrationHasLiveActivity()) {
527
+ return;
528
+ }
529
+ this._taskOrchestrationPollTimer = setTimeout(async () => {
530
+ this._taskOrchestrationPollTimer = 0;
531
+ if (this.mainTab !== 'orchestration') {
532
+ return;
533
+ }
534
+ await this.loadTaskOrchestrationOverview({ silent: true, includeDetail: true });
535
+ }, 4000);
536
+ },
537
+
538
+ resetTaskOrchestrationDraft() {
539
+ const state = this.ensureTaskOrchestrationState();
540
+ state.target = '';
541
+ state.title = '';
542
+ state.notes = '';
543
+ state.followUpsText = '';
544
+ state.workflowIdsText = '';
545
+ state.selectedEngine = 'codex';
546
+ state.runMode = 'write';
547
+ state.concurrency = 2;
548
+ state.autoFixRounds = 1;
549
+ state.plan = null;
550
+ state.planIssues = [];
551
+ state.planWarnings = [];
552
+ state.lastError = '';
553
+ this.syncTaskOrchestrationPolling();
554
+ }
555
+ };
556
+ }