codexmate 0.1.29 → 0.1.31

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 (72) hide show
  1. package/README.md +95 -4
  2. package/README.vi.md +95 -4
  3. package/README.zh.md +96 -4
  4. package/cli/config-bootstrap.js +25 -11
  5. package/cli/skills.js +33 -8
  6. package/cli.js +364 -42
  7. package/lib/cli-config-engine.js +260 -0
  8. package/lib/cli-utils.js +2 -1
  9. package/lib/cli-webhook.js +1 -1
  10. package/lib/handoff-mcp.js +282 -0
  11. package/lib/http-access-control.js +335 -0
  12. package/lib/thread-handoff.js +130 -0
  13. package/lib/web-startup-auth.js +49 -0
  14. package/lib/workflow-engine.js +92 -21
  15. package/lib/workflow-runner.js +261 -0
  16. package/package.json +6 -1
  17. package/web-ui/app.js +33 -4
  18. package/web-ui/logic.sessions.mjs +24 -0
  19. package/web-ui/modules/access-token.mjs +33 -0
  20. package/web-ui/modules/api.mjs +2 -1
  21. package/web-ui/modules/app.computed.dashboard.mjs +1 -1
  22. package/web-ui/modules/app.methods.codex-config.mjs +1 -1
  23. package/web-ui/modules/app.methods.index.mjs +2 -0
  24. package/web-ui/modules/app.methods.navigation.mjs +17 -3
  25. package/web-ui/modules/app.methods.prompts-editor.mjs +7 -0
  26. package/web-ui/modules/app.methods.providers.mjs +2 -2
  27. package/web-ui/modules/app.methods.runtime.mjs +3 -2
  28. package/web-ui/modules/app.methods.session-actions.mjs +3 -0
  29. package/web-ui/modules/app.methods.session-browser.mjs +11 -3
  30. package/web-ui/modules/app.methods.system-prompt.mjs +1 -8
  31. package/web-ui/modules/app.methods.workflows.mjs +41 -0
  32. package/web-ui/modules/i18n/locales/en.mjs +43 -2
  33. package/web-ui/modules/i18n/locales/ja.mjs +43 -2
  34. package/web-ui/modules/i18n/locales/vi.mjs +43 -2
  35. package/web-ui/modules/i18n/locales/zh-tw.mjs +43 -2
  36. package/web-ui/modules/i18n/locales/zh.mjs +43 -2
  37. package/web-ui/modules/i18n.mjs +16 -0
  38. package/web-ui/modules/sessions-filters-url.mjs +3 -0
  39. package/web-ui/modules/skills.computed.mjs +11 -0
  40. package/web-ui/modules/skills.methods.mjs +63 -12
  41. package/web-ui/modules/thread-handoff.mjs +142 -0
  42. package/web-ui/partials/index/layout-footer.html +1 -1
  43. package/web-ui/partials/index/layout-header.html +32 -12
  44. package/web-ui/partials/index/panel-config-claude.html +2 -0
  45. package/web-ui/partials/index/panel-config-codex.html +2 -0
  46. package/web-ui/partials/index/panel-config-kilocode.html +3 -1
  47. package/web-ui/partials/index/panel-config-openclaw.html +2 -0
  48. package/web-ui/partials/index/panel-config-opencode.html +3 -1
  49. package/web-ui/partials/index/panel-config-pi.html +2 -0
  50. package/web-ui/partials/index/panel-dashboard.html +59 -0
  51. package/web-ui/partials/index/panel-market.html +23 -5
  52. package/web-ui/partials/index/panel-prompts.html +28 -16
  53. package/web-ui/partials/index/panel-sessions.html +51 -70
  54. package/web-ui/partials/index/panel-trash.html +3 -0
  55. package/web-ui/partials/index/thread-handoff.html +59 -0
  56. package/web-ui/res/web-ui-render.precompiled.js +1020 -493
  57. package/web-ui/styles/controls-forms.css +9 -0
  58. package/web-ui/styles/dashboard.css +51 -0
  59. package/web-ui/styles/feedback.css +26 -0
  60. package/web-ui/styles/layout-shell.css +66 -2
  61. package/web-ui/styles/modals-core.css +87 -0
  62. package/web-ui/styles/navigation-panels.css +5 -11
  63. package/web-ui/styles/plugins-panel.css +62 -0
  64. package/web-ui/styles/prompts-editor.css +11 -4
  65. package/web-ui/styles/responsive.css +19 -10
  66. package/web-ui/styles/sessions-list.css +19 -1
  67. package/web-ui/styles/sessions-preview.css +224 -140
  68. package/web-ui/styles/sessions-toolbar-trash.css +2 -2
  69. package/web-ui/styles/settings-panel.css +1 -1
  70. package/web-ui/styles/skills-market.css +47 -0
  71. package/web-ui/styles/titles-cards.css +1 -1
  72. package/web-ui/styles/trash-panel.css +43 -6
@@ -166,6 +166,29 @@ function validateWorkflowDefinition(definition, options = {}) {
166
166
  }
167
167
  }
168
168
 
169
+ const pending = steps.filter(step => step && isPlainObject(step));
170
+ const ordered = new Set();
171
+ for (const step of steps) {
172
+ if (!step || !isPlainObject(step)) continue;
173
+ if (step.dependsOn !== undefined && (!Array.isArray(step.dependsOn) || step.dependsOn.some(id => !stepIds.has(id)))) {
174
+ issues.push({ code: 'workflow-dependency-invalid', message: `invalid dependencies: ${step.id}` });
175
+ }
176
+ if (step.retry !== undefined && (!Number.isInteger(step.retry) || step.retry < 0 || step.retry > 5)) {
177
+ issues.push({ code: 'workflow-retry-invalid', message: `retry must be an integer from 0 to 5: ${step.id}` });
178
+ }
179
+ if (step.timeoutMs !== undefined && (!Number.isInteger(step.timeoutMs) || step.timeoutMs < 1)) {
180
+ issues.push({ code: 'workflow-timeout-invalid', message: `timeoutMs must be a positive integer: ${step.id}` });
181
+ }
182
+ }
183
+ while (pending.length && !issues.length) {
184
+ const index = pending.findIndex(step => (step.dependsOn || []).every(id => ordered.has(id)));
185
+ if (index < 0) {
186
+ issues.push({ code: 'workflow-cycle', message: 'workflow dependency cycle' });
187
+ break;
188
+ }
189
+ ordered.add(pending.splice(index, 1)[0].id);
190
+ }
191
+
169
192
  if (issues.length > 0) {
170
193
  return {
171
194
  ok: false,
@@ -191,10 +214,31 @@ async function executeWorkflowDefinition(definition, input = {}, options = {}) {
191
214
  };
192
215
  const steps = Array.isArray(definition && definition.steps) ? definition.steps : [];
193
216
  const logs = [];
217
+ const pendingSteps = [...steps];
218
+ const orderedSteps = [];
219
+ while (pendingSteps.length) {
220
+ const index = pendingSteps.findIndex(step => (step.dependsOn || []).every(id => orderedSteps.some(item => item.id === id)));
221
+ if (index < 0) throw new Error('invalid workflow dependencies');
222
+ orderedSteps.push(pendingSteps.splice(index, 1)[0]);
223
+ }
224
+ let waiting = false;
225
+ let cancelled = false;
226
+ const saveLog = async log => {
227
+ logs.push(log);
228
+ if (options.onProgress) await options.onProgress(log);
229
+ };
194
230
  let overallError = '';
195
231
  let lastOutput = null;
196
232
 
197
- for (const step of steps) {
233
+ for (const step of orderedSteps) {
234
+ if (options.shouldStop && options.shouldStop()) { cancelled = true; break; }
235
+ const saved = (options.resumeSteps || []).find(item => item.id === step.id && ['success', 'skipped'].includes(item.status));
236
+ if (saved) {
237
+ logs.push(saved);
238
+ context.steps[step.id] = saved;
239
+ if (saved.status === 'success') lastOutput = saved.output;
240
+ continue;
241
+ }
198
242
  const stepId = typeof step.id === 'string' ? step.id.trim() : '';
199
243
  const startedStepTs = Date.now();
200
244
  const baseLog = {
@@ -203,6 +247,11 @@ async function executeWorkflowDefinition(definition, input = {}, options = {}) {
203
247
  startedAt: toIso(startedStepTs)
204
248
  };
205
249
 
250
+ if ((step.dependsOn || []).some(id => !context.steps[id] || context.steps[id].status !== 'success')) {
251
+ overallError = `dependency did not succeed: ${stepId}`;
252
+ waiting = true;
253
+ break;
254
+ }
206
255
  const conditionPass = evaluateStepCondition(step.when, context);
207
256
  if (!conditionPass) {
208
257
  const skippedLog = {
@@ -212,7 +261,7 @@ async function executeWorkflowDefinition(definition, input = {}, options = {}) {
212
261
  endedAt: toIso(Date.now()),
213
262
  durationMs: Date.now() - startedStepTs
214
263
  };
215
- logs.push(skippedLog);
264
+ await saveLog(skippedLog);
216
265
  context.steps[stepId] = {
217
266
  status: 'skipped',
218
267
  output: null,
@@ -234,7 +283,7 @@ async function executeWorkflowDefinition(definition, input = {}, options = {}) {
234
283
  endedAt: toIso(Date.now()),
235
284
  durationMs: Date.now() - startedStepTs
236
285
  };
237
- logs.push(failedLog);
286
+ await saveLog(failedLog);
238
287
  context.steps[stepId] = {
239
288
  status: 'failed',
240
289
  output: null,
@@ -242,6 +291,7 @@ async function executeWorkflowDefinition(definition, input = {}, options = {}) {
242
291
  args: resolvedArgs
243
292
  };
244
293
  overallError = error;
294
+ waiting = true;
245
295
  if (!step.continueOnError) {
246
296
  break;
247
297
  }
@@ -257,7 +307,7 @@ async function executeWorkflowDefinition(definition, input = {}, options = {}) {
257
307
  endedAt: toIso(Date.now()),
258
308
  durationMs: Date.now() - startedStepTs
259
309
  };
260
- logs.push(dryRunLog);
310
+ await saveLog(dryRunLog);
261
311
  context.steps[stepId] = {
262
312
  status: 'skipped',
263
313
  output: null,
@@ -269,22 +319,38 @@ async function executeWorkflowDefinition(definition, input = {}, options = {}) {
269
319
 
270
320
  let payload;
271
321
  let stepError = '';
272
- try {
273
- payload = await invokeTool(baseLog.tool, resolvedArgs, {
274
- step,
275
- context,
276
- allowWrite,
277
- dryRun
278
- });
279
- if (isFailurePayload(payload)) {
280
- stepError = typeof payload.error === 'string' && payload.error.trim()
281
- ? payload.error.trim()
282
- : `step failed: ${stepId || baseLog.tool}`;
322
+ let attempts = 0;
323
+ const retryBudget = isWriteStep ? 0 : (step.retry || 0);
324
+ do {
325
+ attempts += 1;
326
+ if (options.onBeforeStep) await options.onBeforeStep(step);
327
+ const controller = typeof AbortController === 'function' ? new AbortController() : null;
328
+ let timedOut = false;
329
+ const timer = step.timeoutMs ? setTimeout(() => {
330
+ timedOut = true;
331
+ if (controller) controller.abort();
332
+ }, step.timeoutMs) : null;
333
+ try {
334
+ payload = await invokeTool(baseLog.tool, resolvedArgs, {
335
+ step, context, allowWrite, dryRun,
336
+ signal: controller ? controller.signal : undefined
337
+ });
338
+ stepError = isFailurePayload(payload) ? (payload.error || `step failed: ${stepId}`) : '';
339
+ } catch (error) {
340
+ stepError = error.message || String(error);
341
+ payload = { error: stepError, retryable: error.retryable === true };
342
+ } finally {
343
+ if (timer) clearTimeout(timer);
283
344
  }
284
- } catch (error) {
285
- stepError = error && error.message ? error.message : String(error || 'step execution failed');
286
- payload = { error: stepError };
287
- }
345
+ if (timedOut) {
346
+ stepError = `step exceeded timeout; execution has settled: ${stepId}`;
347
+ payload = { error: stepError, blocked: true };
348
+ }
349
+ if (!stepError || !payload.retryable || payload.blocked || attempts > retryBudget) break;
350
+ if (options.shouldStop && options.shouldStop()) break;
351
+ await new Promise(resolve => setTimeout(resolve, 100 * Math.pow(2, attempts - 1)));
352
+ } while (true);
353
+ if (payload && payload.blocked) waiting = true;
288
354
 
289
355
  const status = stepError ? 'failed' : 'success';
290
356
  const endedAtTs = Date.now();
@@ -293,14 +359,16 @@ async function executeWorkflowDefinition(definition, input = {}, options = {}) {
293
359
  args: resolvedArgs,
294
360
  status,
295
361
  output: payload,
362
+ attempts,
296
363
  error: stepError,
297
364
  endedAt: toIso(endedAtTs),
298
365
  durationMs: endedAtTs - startedStepTs
299
366
  };
300
- logs.push(stepLog);
367
+ await saveLog(stepLog);
301
368
  context.steps[stepId] = {
302
369
  status,
303
370
  output: payload,
371
+ attempts,
304
372
  error: stepError,
305
373
  args: resolvedArgs
306
374
  };
@@ -315,10 +383,13 @@ async function executeWorkflowDefinition(definition, input = {}, options = {}) {
315
383
  }
316
384
  }
317
385
 
386
+ if (options.shouldStop && options.shouldStop()) cancelled = true;
318
387
  const endedAtTs = Date.now();
319
388
  const hasFailed = logs.some((item) => item.status === 'failed');
320
389
  const result = {
321
- success: !hasFailed,
390
+ success: !hasFailed && !waiting && !cancelled,
391
+ waiting,
392
+ cancelled,
322
393
  startedAt: toIso(startedAtTs),
323
394
  endedAt: toIso(endedAtTs),
324
395
  durationMs: endedAtTs - startedAtTs,
@@ -0,0 +1,261 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { randomBytes } = require('crypto');
6
+ const randomUUID = () => randomBytes(16).toString('hex');
7
+ const { executeWorkflowDefinition } = require('./workflow-engine');
8
+
9
+ const TERMINAL = new Set(['completed', 'failed', 'cancelled']);
10
+ const clone = value => JSON.parse(JSON.stringify(value));
11
+ const now = () => new Date().toISOString();
12
+ const message = error => error instanceof Error ? error.message : String(error);
13
+
14
+ function createWorkflowRunner({ directory, execute = executeWorkflowDefinition, notify } = {}) {
15
+ if (!directory) throw new TypeError('directory is required');
16
+ if (typeof execute !== 'function') throw new TypeError('execute must be a function');
17
+ fs.mkdirSync(directory, { recursive: true });
18
+ const runs = new Map();
19
+ const live = new Set();
20
+ const notifying = new Set();
21
+ const adapters = new Map();
22
+
23
+ function save(run) {
24
+ run.updatedAt = now();
25
+ const destination = path.join(directory, `${run.id}.json`);
26
+ const temporary = `${destination}.${randomUUID()}.tmp`;
27
+ try {
28
+ fs.writeFileSync(temporary, JSON.stringify(run, null, 2), { flag: 'wx', mode: 0o600 });
29
+ fs.renameSync(temporary, destination);
30
+ } finally {
31
+ if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
32
+ }
33
+ }
34
+
35
+ for (const file of fs.readdirSync(directory)) {
36
+ if (!file.endsWith('.json')) continue;
37
+ const run = JSON.parse(fs.readFileSync(path.join(directory, file), 'utf8'));
38
+ if (file !== `${run.id}.json`) throw new Error(`Invalid workflow run file: ${file}`);
39
+ runs.set(run.id, run);
40
+ }
41
+
42
+ function requireRun(id) {
43
+ const run = runs.get(id);
44
+ if (!run) throw new Error(`Unknown workflow run: ${id}`);
45
+ return run;
46
+ }
47
+
48
+ function summarize(run) {
49
+ const completed = run.steps.filter(step => step.status === 'success');
50
+ const done = new Set(run.steps.filter(step => ['success', 'skipped'].includes(step.status)).map(step => step.id));
51
+ return {
52
+ completed: clone(completed),
53
+ result: run.status === 'completed' ? clone(run.output) : null,
54
+ unfinished: (run.definition.steps || []).filter(step => !done.has(step.id)).map(step => ({
55
+ id: step.id,
56
+ reason: run.reason || run.error || run.status
57
+ }))
58
+ };
59
+ }
60
+
61
+ function notifyLater(run) {
62
+ if (typeof notify !== 'function' || notifying.has(run.id)) return;
63
+ if (!['pending', 'sending'].includes(run.notification.status)) return;
64
+ notifying.add(run.id);
65
+ Promise.resolve().then(async () => {
66
+ run.notification.status = 'sending';
67
+ run.notification.attempts += 1;
68
+ save(run);
69
+ try {
70
+ const delivery = await notify(clone(run));
71
+ if (delivery && delivery.ok === false && !delivery.skipped) throw new Error(delivery.error || 'notification failed');
72
+ run.notification.status = delivery && delivery.skipped ? 'skipped' : 'sent';
73
+ run.notification.error = '';
74
+ } catch (error) {
75
+ run.notification.status = 'failed';
76
+ run.notification.error = message(error);
77
+ }
78
+ run.notification.endedAt = now();
79
+ save(run);
80
+ }).finally(() => notifying.delete(run.id)).catch(error => {
81
+ run.notification.status = 'failed';
82
+ run.notification.error = message(error);
83
+ });
84
+ }
85
+
86
+ function finish(run, status, reason = '') {
87
+ run.status = status;
88
+ run.reason = reason;
89
+ run.activeStep = null;
90
+ run.endedAt = TERMINAL.has(status) ? now() : null;
91
+ run.summary = summarize(run);
92
+ run.notification = {
93
+ status: typeof notify === 'function' ? 'pending' : 'disabled',
94
+ attempts: 0,
95
+ error: ''
96
+ };
97
+ save(run);
98
+ notifyLater(run);
99
+ }
100
+
101
+ function record(run, log) {
102
+ const saved = clone(log);
103
+ const index = run.steps.findIndex(item => item.id === saved.id);
104
+ if (index < 0) run.steps.push(saved);
105
+ else run.steps[index] = saved;
106
+ run.logs.push(saved);
107
+ if (!run.activeStep || run.activeStep.id === saved.id) run.activeStep = null;
108
+ save(run);
109
+ }
110
+
111
+ async function advance(run) {
112
+ const options = adapters.get(run.id) || {};
113
+ if (run.status === 'cancelling') {
114
+ finish(run, 'cancelled', 'cancelled by user');
115
+ return;
116
+ }
117
+ run.status = 'running';
118
+ run.attempts += 1;
119
+ run.startedAt = run.startedAt || now();
120
+ run.endedAt = null;
121
+ save(run);
122
+ const resumeSteps = run.steps.filter(step => ['success', 'skipped'].includes(step.status));
123
+ try {
124
+ const execution = await execute(clone(run.definition), clone(run.input), {
125
+ ...options,
126
+ allowWrite: run.options.allowWrite,
127
+ dryRun: run.options.dryRun,
128
+ resumeSteps: clone(resumeSteps),
129
+ shouldStop: () => run.status === 'cancelling',
130
+ onBeforeStep: async step => {
131
+ if (run.status === 'cancelling') throw new Error('cancelled by user');
132
+ run.activeStep = clone(step);
133
+ run.stepAttempts[step.id] = (run.stepAttempts[step.id] || 0) + 1;
134
+ save(run);
135
+ if (options.onBeforeStep) await options.onBeforeStep(clone(step));
136
+ },
137
+ onProgress: async log => {
138
+ record(run, log);
139
+ if (options.onProgress) await options.onProgress(clone(log));
140
+ }
141
+ });
142
+ run.execution = clone(execution);
143
+ run.output = execution.output === undefined ? null : clone(execution.output);
144
+ for (const log of execution.steps || []) {
145
+ const previous = run.steps.find(item => item.id === log.id);
146
+ if (!previous || JSON.stringify(previous) !== JSON.stringify(log)) record(run, log);
147
+ }
148
+ run.error = execution.error || '';
149
+ if (run.status === 'cancelling' || execution.cancelled) finish(run, 'cancelled', run.error || 'cancelled by user');
150
+ else if (execution.waiting) finish(run, 'waiting', run.error || execution.reason || 'execution requires explicit resume');
151
+ else finish(run, execution.success ? 'completed' : 'failed', run.error);
152
+ } catch (error) {
153
+ run.error = message(error);
154
+ // A rejected engine may leave a side effect in flight or unacknowledged.
155
+ // Keep the active step for recovery instead of assuming it completed.
156
+ if (run.activeStep) {
157
+ const activeStep = run.activeStep;
158
+ finish(run, 'waiting', run.error);
159
+ run.activeStep = activeStep;
160
+ save(run);
161
+ } else {
162
+ finish(run, run.status === 'cancelling' ? 'cancelled' : 'failed', run.error);
163
+ }
164
+ }
165
+ }
166
+
167
+ function schedule(run) {
168
+ if (live.has(run.id)) return;
169
+ live.add(run.id);
170
+ Promise.resolve().then(() => advance(run)).finally(() => live.delete(run.id)).catch(error => {
171
+ // Persistence errors must stop execution, never trigger another attempt.
172
+ run.error = message(error);
173
+ run.status = 'waiting';
174
+ });
175
+ }
176
+
177
+ function submit(definition, input = {}, options = {}) {
178
+ const run = {
179
+ id: randomUUID(),
180
+ definition: clone(definition),
181
+ input: clone(input),
182
+ options: { allowWrite: options.allowWrite === true, dryRun: options.dryRun === true },
183
+ status: 'queued',
184
+ createdAt: now(),
185
+ updatedAt: now(),
186
+ startedAt: null,
187
+ endedAt: null,
188
+ attempts: 0,
189
+ stepAttempts: {},
190
+ steps: clone(options.resumeSteps || []),
191
+ logs: [],
192
+ activeStep: null,
193
+ execution: null,
194
+ output: null,
195
+ error: '',
196
+ reason: '',
197
+ summary: null,
198
+ notification: { status: 'idle', attempts: 0, error: '' }
199
+ };
200
+ save(run);
201
+ runs.set(run.id, run);
202
+ adapters.set(run.id, options);
203
+ schedule(run);
204
+ return clone(run);
205
+ }
206
+
207
+ function resume(id, options = {}) {
208
+ const run = requireRun(id);
209
+ if (live.has(id) || run.status !== 'waiting') throw new Error(`Run is not waiting: ${id}`);
210
+ if (Object.prototype.hasOwnProperty.call(options, 'input')) run.input = clone(options.input);
211
+ if (Object.prototype.hasOwnProperty.call(options, 'allowWrite')) run.options.allowWrite = options.allowWrite === true;
212
+ run.status = 'queued';
213
+ run.reason = '';
214
+ run.error = '';
215
+ run.activeStep = null;
216
+ save(run);
217
+ schedule(run);
218
+ return clone(run);
219
+ }
220
+
221
+ function cancel(id) {
222
+ const run = requireRun(id);
223
+ if (TERMINAL.has(run.status)) return clone(run);
224
+ if (live.has(id)) {
225
+ run.status = 'cancelling';
226
+ save(run);
227
+ } else finish(run, 'cancelled', 'cancelled by user');
228
+ return clone(run);
229
+ }
230
+
231
+ function recover() {
232
+ for (const run of runs.values()) {
233
+ if (live.has(run.id)) continue;
234
+ if (TERMINAL.has(run.status) || run.status === 'waiting') {
235
+ notifyLater(run);
236
+ continue;
237
+ }
238
+ if (run.status === 'cancelling') {
239
+ if (run.activeStep) finish(run, 'waiting', 'interrupted cancellation requires explicit resume');
240
+ else finish(run, 'cancelled', 'cancelled by user');
241
+ continue;
242
+ }
243
+ if (run.activeStep) {
244
+ const step = (run.definition.steps || []).find(item => item.id === run.activeStep.id);
245
+ // Only an explicitly read-only definition is safe to replay.
246
+ if (!step || step.write !== false) {
247
+ finish(run, 'waiting', 'interrupted write or unclassified step requires explicit resume');
248
+ continue;
249
+ }
250
+ }
251
+ schedule(run);
252
+ }
253
+ return list();
254
+ }
255
+
256
+ function list() { return Array.from(runs.values(), run => clone(run)); }
257
+ function get(id) { return runs.has(id) ? clone(runs.get(id)) : null; }
258
+ return { submit, list, get, resume, cancel, recover };
259
+ }
260
+
261
+ module.exports = { createWorkflowRunner };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexmate",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "Codex/Claude Code/OpenClaw 配置、会话与任务编排 CLI + Web 工具",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -41,6 +41,9 @@
41
41
  "test:ci": "node tools/ci/run-check.js all",
42
42
  "test:unit": "node tests/unit/run.mjs",
43
43
  "test:e2e": "node tests/e2e/run.js",
44
+ "test:e2e:browser": "e2e run",
45
+ "test:e2e:browser:install": "e2e-web install chromium --with-deps",
46
+ "test:e2e:browser:list": "e2e list",
44
47
  "setup:git": "git remote set-url origin https://github.com/SakuraByteCore/codexmate.git && gh auth setup-git",
45
48
  "reset:dev": "node tools/dev/reset-and-dev.js",
46
49
  "pretest": "node tools/ci/ensure-test-deps.js"
@@ -72,7 +75,9 @@
72
75
  "author": "ymkiux",
73
76
  "license": "Apache-2.0",
74
77
  "devDependencies": {
78
+ "@e2e-dev/web": "0.15.4",
75
79
  "@vue/compiler-dom": "^3.5.34",
80
+ "e2e": "0.22.0",
76
81
  "opencc-js": "^1.3.1",
77
82
  "vitepress": "^1.6.4"
78
83
  }
package/web-ui/app.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { threadHandoffMixin } from './modules/thread-handoff.mjs';
1
2
  import {
2
3
  DEFAULT_MODEL_AUTO_COMPACT_TOKEN_LIMIT,
3
4
  DEFAULT_MODEL_CONTEXT_WINDOW,
@@ -57,11 +58,17 @@ document.addEventListener('DOMContentLoaded', () => {
57
58
  });
58
59
 
59
60
  const appOptions = {
61
+ mixins: [threadHandoffMixin],
60
62
  data() {
61
63
  return {
64
+ workflowDefinitions: [], workflowRuns: [], workflowId: 'diagnose-config',
65
+ workflowInput: '{}', workflowAllowWrite: false, workflowBusy: false, workflowError: '',
66
+ workflowTimer: null,
62
67
  lang: 'zh',
68
+ languageMenuOpen: false,
63
69
  appVersion: '',
64
70
  mainTab: 'dashboard',
71
+ navigationReady: false,
65
72
  configMode: 'codex',
66
73
  currentProvider: '',
67
74
  currentModel: '',
@@ -264,6 +271,7 @@ document.addEventListener('DOMContentLoaded', () => {
264
271
  skillsRootPath: '',
265
272
  skillsList: [],
266
273
  skillsSelectedNames: [],
274
+ skillsMarketSelectedNames: [],
267
275
  skillsLoading: false,
268
276
  skillsDeleting: false,
269
277
  skillsKeyword: '',
@@ -274,6 +282,7 @@ document.addEventListener('DOMContentLoaded', () => {
274
282
  skillsImporting: false,
275
283
  skillsZipImporting: false,
276
284
  skillsExporting: false,
285
+ skillsBackingUp: false,
277
286
  skillsMarketLoading: false,
278
287
  skillsMarketLocalLoadedOnce: false,
279
288
  skillsMarketImportLoadedOnce: false,
@@ -333,7 +342,6 @@ document.addEventListener('DOMContentLoaded', () => {
333
342
  opencode: 0
334
343
  },
335
344
  sessionExporting: {},
336
- sessionExportRange: 'default',
337
345
  sessionExportNotice: null,
338
346
  sessionSearchInfo: null,
339
347
  sessionConverting: {},
@@ -582,7 +590,7 @@ document.addEventListener('DOMContentLoaded', () => {
582
590
  sessionLoadNativeDialog: false,
583
591
  starPrompted: false,
584
592
  webhookConfig: { enabled: false, url: '', events: ['provider-switch', 'claude-md-edit'] },
585
- webhookEventOptions: ['provider-switch', 'claude-md-edit'],
593
+ webhookEventOptions: ['provider-switch', 'claude-md-edit', 'workflow-completed', 'workflow-failed', 'workflow-waiting'],
586
594
  webhookSaving: false,
587
595
  webhookTestResult: null,
588
596
  webhookTesting: false,
@@ -590,6 +598,8 @@ document.addEventListener('DOMContentLoaded', () => {
590
598
  },
591
599
 
592
600
  mounted() {
601
+ this.refreshWorkflowRuns();
602
+ this.workflowTimer = setInterval(() => this.refreshWorkflowRuns(), 3000);
593
603
  // URL 规范化:将 /web-ui/* 重定向到根路径 /
594
604
  try {
595
605
  const pathname = window.location.pathname;
@@ -624,11 +634,16 @@ document.addEventListener('DOMContentLoaded', () => {
624
634
  return true;
625
635
  }
626
636
  })();
627
- this.loadWebUiPreferences({ applyNavigation: applyPreferenceNavigation }).then(() => {
637
+ const preferencesReady = this.loadWebUiPreferences({ applyNavigation: applyPreferenceNavigation });
638
+ preferencesReady.then(() => {
628
639
  if (this.mainTab === 'prompts' && typeof this.loadPromptsTabContent === 'function') {
629
640
  this.loadPromptsTabContent();
630
641
  }
642
+ }).finally(() => {
643
+ this.navigationReady = true;
631
644
  });
645
+ } else {
646
+ this.navigationReady = true;
632
647
  }
633
648
  if (typeof this.t === 'function') {
634
649
  this.confirmDialogConfirmText = this.t('confirm.ok');
@@ -723,7 +738,14 @@ document.addEventListener('DOMContentLoaded', () => {
723
738
  const runInitialLoad = () => {
724
739
  const triggerLoad = async () => {
725
740
  this._initialLoadTimer = 0;
726
- const startupOk = await this.loadAll();
741
+ const sessionStartup = this.mainTab === 'sessions';
742
+ if (sessionStartup) {
743
+ this.loading = false;
744
+ if (!this.sessionsLoadedOnce && !this.sessionsLoading) {
745
+ await this.loadSessions();
746
+ }
747
+ }
748
+ const startupOk = await this.loadAll({ preserveLoading: sessionStartup });
727
749
  if (!startupOk) {
728
750
  return;
729
751
  }
@@ -750,6 +772,12 @@ document.addEventListener('DOMContentLoaded', () => {
750
772
  void this.loadProviderCacheRecords({ background: true });
751
773
  }
752
774
  };
775
+ if (typeof this.scheduleAfterFrame === 'function') {
776
+ this.scheduleAfterFrame(() => {
777
+ this._initialLoadTimer = setTimeout(triggerLoad, 0);
778
+ });
779
+ return;
780
+ }
753
781
  if (typeof requestAnimationFrame === 'function') {
754
782
  this._initialLoadRafId = requestAnimationFrame(() => {
755
783
  this._initialLoadRafId = 0;
@@ -782,6 +810,7 @@ document.addEventListener('DOMContentLoaded', () => {
782
810
  },
783
811
 
784
812
  beforeUnmount() {
813
+ clearInterval(this.workflowTimer);
785
814
  this.teardownSessionTabRender();
786
815
  this.cancelScheduledSessionTabDeferredTeardown();
787
816
  this.disconnectSessionPreviewHeaderResizeObserver();
@@ -2,6 +2,30 @@ export const DEFAULT_SESSION_CONTENT_SCAN_LIMIT = 50;
2
2
  export const DEFAULT_SESSION_LIST_LIMIT = 200;
3
3
  export const DEFAULT_SESSION_LIST_FAST_LIMIT = 20;
4
4
 
5
+
6
+ function decodeSessionTitleValue(value) {
7
+ return String(value || '')
8
+ .replace(/\x26quot;/gi, '"')
9
+ .replace(/\x26apos;/gi, "'")
10
+ .replace(/\x26lt;/gi, '<')
11
+ .replace(/\x26gt;/gi, '>')
12
+ .replace(/\x26amp;/gi, '&')
13
+ .trim();
14
+ }
15
+
16
+ export function parseSessionTitleInfo(session = {}) {
17
+ const rawTitle = typeof session.title === 'string' ? session.title.trim() : '';
18
+ const skillTag = rawTitle.match(/<skill\b([^>]*)>/i);
19
+ const attributes = {};
20
+ const attributePattern = /([\w:-]+)\s*=\s*(["'])(.*?)\2/g;
21
+ let match;
22
+ while ((match = attributePattern.exec(skillTag ? skillTag[1] : '')) !== null) {
23
+ attributes[match[1].toLowerCase()] = decodeSessionTitleValue(match[3]);
24
+ }
25
+ const title = attributes.name || (skillTag ? '' : rawTitle) || session.sessionId || '';
26
+ const location = attributes.location || (typeof session.cwd === 'string' ? session.cwd.trim() : '');
27
+ return { title, location };
28
+ }
5
29
  function shouldUseFastSessionBrowseLimit(options = {}) {
6
30
  if (options.forceRefresh) {
7
31
  return false;
@@ -0,0 +1,33 @@
1
+ const accessTokenLocation = typeof location !== 'undefined' ? location : null;
2
+ const initialAccessToken = (() => {
3
+ try { return accessTokenLocation ? new URL(accessTokenLocation.href).searchParams.get('token') || '' : ''; }
4
+ catch (_) { return ''; }
5
+ })();
6
+
7
+ export function getAccessToken() {
8
+ if (!accessTokenLocation) return '';
9
+ try {
10
+ return new URL(accessTokenLocation.href).searchParams.get('token') || initialAccessToken;
11
+ } catch (_) {
12
+ return '';
13
+ }
14
+ }
15
+
16
+ export function withAccessToken(url) {
17
+ const token = getAccessToken();
18
+ if (!token) return url;
19
+ try {
20
+ const parsed = new URL(url, accessTokenLocation && accessTokenLocation.origin ? accessTokenLocation.origin : 'http://localhost');
21
+ parsed.searchParams.set('token', token);
22
+ return parsed.pathname.startsWith('/') && accessTokenLocation && accessTokenLocation.origin
23
+ ? `${parsed.pathname}${parsed.search}${parsed.hash}`
24
+ : parsed.toString();
25
+ } catch (_) {
26
+ return url;
27
+ }
28
+ }
29
+
30
+ export function authorizationHeaders(extra = {}) {
31
+ const token = getAccessToken();
32
+ return token ? { ...extra, Authorization: `Bearer ${token}` } : { ...extra };
33
+ }
@@ -1,3 +1,4 @@
1
+ import { authorizationHeaders } from './access-token.mjs';
1
2
  const browserLocation = typeof location !== 'undefined' ? location : null;
2
3
 
3
4
  export const API_BASE = (browserLocation && browserLocation.origin && browserLocation.origin !== 'null')
@@ -7,7 +8,7 @@ export const API_BASE = (browserLocation && browserLocation.origin && browserLoc
7
8
  async function postApi(action, params = {}) {
8
9
  return await fetch(`${API_BASE}/api`, {
9
10
  method: 'POST',
10
- headers: { 'Content-Type': 'application/json' },
11
+ headers: authorizationHeaders({ 'Content-Type': 'application/json' }),
11
12
  body: JSON.stringify({ action, params })
12
13
  });
13
14
  }