codexmate 0.1.30 → 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.
- package/README.md +95 -4
- package/README.vi.md +95 -4
- package/README.zh.md +96 -4
- package/cli/config-bootstrap.js +25 -11
- package/cli.js +360 -44
- package/lib/cli-config-engine.js +260 -0
- package/lib/cli-utils.js +2 -1
- package/lib/cli-webhook.js +1 -1
- package/lib/handoff-mcp.js +282 -0
- package/lib/http-access-control.js +335 -0
- package/lib/thread-handoff.js +130 -0
- package/lib/web-startup-auth.js +49 -0
- package/lib/workflow-engine.js +92 -21
- package/lib/workflow-runner.js +261 -0
- package/package.json +1 -1
- package/web-ui/app.js +23 -2
- package/web-ui/modules/access-token.mjs +33 -0
- package/web-ui/modules/api.mjs +2 -1
- package/web-ui/modules/app.methods.index.mjs +2 -0
- package/web-ui/modules/app.methods.navigation.mjs +17 -3
- package/web-ui/modules/app.methods.prompts-editor.mjs +7 -0
- package/web-ui/modules/app.methods.providers.mjs +2 -2
- package/web-ui/modules/app.methods.runtime.mjs +3 -2
- package/web-ui/modules/app.methods.session-actions.mjs +3 -0
- package/web-ui/modules/app.methods.session-browser.mjs +6 -2
- package/web-ui/modules/app.methods.workflows.mjs +41 -0
- package/web-ui/modules/i18n/locales/en.mjs +37 -2
- package/web-ui/modules/i18n/locales/ja.mjs +37 -2
- package/web-ui/modules/i18n/locales/vi.mjs +37 -2
- package/web-ui/modules/i18n/locales/zh-tw.mjs +37 -2
- package/web-ui/modules/i18n/locales/zh.mjs +37 -2
- package/web-ui/modules/sessions-filters-url.mjs +3 -0
- package/web-ui/modules/skills.methods.mjs +6 -5
- package/web-ui/modules/thread-handoff.mjs +142 -0
- package/web-ui/partials/index/panel-config-claude.html +2 -0
- package/web-ui/partials/index/panel-config-codex.html +2 -0
- package/web-ui/partials/index/panel-config-kilocode.html +3 -1
- package/web-ui/partials/index/panel-config-openclaw.html +2 -0
- package/web-ui/partials/index/panel-config-opencode.html +3 -1
- package/web-ui/partials/index/panel-config-pi.html +2 -0
- package/web-ui/partials/index/panel-dashboard.html +59 -0
- package/web-ui/partials/index/panel-prompts.html +28 -16
- package/web-ui/partials/index/panel-sessions.html +21 -33
- package/web-ui/partials/index/thread-handoff.html +59 -0
- package/web-ui/res/web-ui-render.precompiled.js +614 -152
- package/web-ui/styles/controls-forms.css +9 -0
- package/web-ui/styles/dashboard.css +51 -0
- package/web-ui/styles/modals-core.css +87 -0
- package/web-ui/styles/navigation-panels.css +1 -1
- package/web-ui/styles/plugins-panel.css +62 -0
- package/web-ui/styles/prompts-editor.css +11 -4
- package/web-ui/styles/responsive.css +19 -10
- package/web-ui/styles/sessions-preview.css +185 -111
package/lib/workflow-engine.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
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
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,8 +58,12 @@ 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',
|
|
63
68
|
languageMenuOpen: false,
|
|
64
69
|
appVersion: '',
|
|
@@ -585,7 +590,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
585
590
|
sessionLoadNativeDialog: false,
|
|
586
591
|
starPrompted: false,
|
|
587
592
|
webhookConfig: { enabled: false, url: '', events: ['provider-switch', 'claude-md-edit'] },
|
|
588
|
-
webhookEventOptions: ['provider-switch', 'claude-md-edit'],
|
|
593
|
+
webhookEventOptions: ['provider-switch', 'claude-md-edit', 'workflow-completed', 'workflow-failed', 'workflow-waiting'],
|
|
589
594
|
webhookSaving: false,
|
|
590
595
|
webhookTestResult: null,
|
|
591
596
|
webhookTesting: false,
|
|
@@ -593,6 +598,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
593
598
|
},
|
|
594
599
|
|
|
595
600
|
mounted() {
|
|
601
|
+
this.refreshWorkflowRuns();
|
|
602
|
+
this.workflowTimer = setInterval(() => this.refreshWorkflowRuns(), 3000);
|
|
596
603
|
// URL 规范化:将 /web-ui/* 重定向到根路径 /
|
|
597
604
|
try {
|
|
598
605
|
const pathname = window.location.pathname;
|
|
@@ -731,7 +738,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
731
738
|
const runInitialLoad = () => {
|
|
732
739
|
const triggerLoad = async () => {
|
|
733
740
|
this._initialLoadTimer = 0;
|
|
734
|
-
const
|
|
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 });
|
|
735
749
|
if (!startupOk) {
|
|
736
750
|
return;
|
|
737
751
|
}
|
|
@@ -758,6 +772,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
758
772
|
void this.loadProviderCacheRecords({ background: true });
|
|
759
773
|
}
|
|
760
774
|
};
|
|
775
|
+
if (typeof this.scheduleAfterFrame === 'function') {
|
|
776
|
+
this.scheduleAfterFrame(() => {
|
|
777
|
+
this._initialLoadTimer = setTimeout(triggerLoad, 0);
|
|
778
|
+
});
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
761
781
|
if (typeof requestAnimationFrame === 'function') {
|
|
762
782
|
this._initialLoadRafId = requestAnimationFrame(() => {
|
|
763
783
|
this._initialLoadRafId = 0;
|
|
@@ -790,6 +810,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
790
810
|
},
|
|
791
811
|
|
|
792
812
|
beforeUnmount() {
|
|
813
|
+
clearInterval(this.workflowTimer);
|
|
793
814
|
this.teardownSessionTabRender();
|
|
794
815
|
this.cancelScheduledSessionTabDeferredTeardown();
|
|
795
816
|
this.disconnectSessionPreviewHeaderResizeObserver();
|
|
@@ -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
|
+
}
|
package/web-ui/modules/api.mjs
CHANGED
|
@@ -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
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createWorkflowMethods } from './app.methods.workflows.mjs';
|
|
1
2
|
import {
|
|
2
3
|
API_BASE,
|
|
3
4
|
api,
|
|
@@ -53,6 +54,7 @@ import {
|
|
|
53
54
|
export function createAppMethods() {
|
|
54
55
|
return {
|
|
55
56
|
...createI18nMethods(),
|
|
57
|
+
...createWorkflowMethods({ api }),
|
|
56
58
|
...createPromptsEditorMethods({ api }),
|
|
57
59
|
...createWebhookMethods(),
|
|
58
60
|
...createStartupClaudeMethods({
|
|
@@ -86,8 +86,10 @@
|
|
|
86
86
|
pathname = '/';
|
|
87
87
|
}
|
|
88
88
|
url.pathname = pathname;
|
|
89
|
+
const accessToken = url.searchParams.get('token') || '';
|
|
89
90
|
url.search = '';
|
|
90
91
|
url.hash = '';
|
|
92
|
+
if (accessToken) url.searchParams.set('token', accessToken);
|
|
91
93
|
const nextUrl = url.toString();
|
|
92
94
|
if (nextUrl === window.location.href) return;
|
|
93
95
|
if (window.history && typeof window.history.replaceState === 'function') {
|
|
@@ -610,11 +612,23 @@
|
|
|
610
612
|
|
|
611
613
|
scheduleAfterFrame(task) {
|
|
612
614
|
const callback = typeof task === 'function' ? task : () => {};
|
|
615
|
+
const fallbackDelayMs = 100;
|
|
616
|
+
let completed = false;
|
|
617
|
+
let frameId;
|
|
618
|
+
let timer;
|
|
619
|
+
const run = () => {
|
|
620
|
+
if (completed) return;
|
|
621
|
+
completed = true;
|
|
622
|
+
clearTimeout(timer);
|
|
623
|
+
if (frameId !== undefined && typeof cancelAnimationFrame === 'function') {
|
|
624
|
+
cancelAnimationFrame(frameId);
|
|
625
|
+
}
|
|
626
|
+
callback();
|
|
627
|
+
};
|
|
628
|
+
timer = setTimeout(run, fallbackDelayMs);
|
|
613
629
|
if (typeof requestAnimationFrame === 'function') {
|
|
614
|
-
requestAnimationFrame(
|
|
615
|
-
return;
|
|
630
|
+
frameId = requestAnimationFrame(run);
|
|
616
631
|
}
|
|
617
|
-
setTimeout(callback, 16);
|
|
618
632
|
},
|
|
619
633
|
scheduleIdleTask(task, timeoutMs = 160) {
|
|
620
634
|
const callback = typeof task === 'function' ? task : () => {};
|
|
@@ -78,6 +78,13 @@ export function createPromptsEditorMethods(options = {}) {
|
|
|
78
78
|
promptsEditorMeta(key) {
|
|
79
79
|
return PROMPTS_EDITOR_META[key] || null;
|
|
80
80
|
},
|
|
81
|
+
promptPathFileName(path) {
|
|
82
|
+
const normalized = typeof path === 'string' ? path.trim() : '';
|
|
83
|
+
if (!normalized) {
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
86
|
+
return normalized.split(/[\\/]/).filter(Boolean).pop() || normalized;
|
|
87
|
+
},
|
|
81
88
|
|
|
82
89
|
|
|
83
90
|
refreshPromptsPreview(key) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { nextCodexProviderName } from './provider-default-names.mjs';
|
|
2
2
|
|
|
3
|
-
const PROVIDER_NAME_PATTERN = /^[a-zA-Z0-
|
|
3
|
+
const PROVIDER_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
4
4
|
const RESERVED_PROXY_PROVIDER_NAME = 'codexmate-proxy';
|
|
5
5
|
const RESERVED_LOCAL_PROVIDER_NAME = 'local';
|
|
6
6
|
|
|
@@ -88,7 +88,7 @@ function getProviderValidationForContext(vm, mode = 'add') {
|
|
|
88
88
|
if (!name) {
|
|
89
89
|
errors.name = '名称不能为空';
|
|
90
90
|
} else if (!isValidProviderNameInputValue(name)) {
|
|
91
|
-
errors.name = '
|
|
91
|
+
errors.name = '名称仅支持字母/数字/_-';
|
|
92
92
|
} else if (isReservedProviderCreationNameInput(name)) {
|
|
93
93
|
errors.name = 'codexmate-proxy 为保留名称,不可手动添加';
|
|
94
94
|
} else if (findProviderByName(vm.providersList, name)) {
|