codexmate 0.0.24 → 0.0.25
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 +28 -6
- package/README.zh.md +29 -7
- package/cli/builtin-proxy.js +35 -0
- package/cli/claude-proxy.js +24 -0
- package/cli/import-skills-url.js +23 -1
- package/cli/openai-bridge.js +51 -4
- package/cli/session-usage.js +8 -2
- package/cli.js +1543 -117
- package/lib/automation.js +404 -0
- package/lib/cli-path-utils.js +21 -5
- package/lib/cli-sessions.js +32 -1
- package/lib/download-artifacts.js +17 -2
- package/lib/mcp-stdio.js +13 -0
- package/package.json +2 -5
- package/web-ui/app.js +6 -3
- package/web-ui/logic.sessions.mjs +2 -2
- package/web-ui/modules/app.computed.dashboard.mjs +2 -0
- package/web-ui/modules/app.computed.session.mjs +17 -0
- package/web-ui/modules/app.methods.install.mjs +28 -0
- package/web-ui/modules/app.methods.session-actions.mjs +8 -1
- package/web-ui/modules/app.methods.session-browser.mjs +28 -4
- package/web-ui/modules/app.methods.session-trash.mjs +4 -2
- package/web-ui/modules/i18n.dict.mjs +24 -8
- package/web-ui/partials/index/layout-header.html +12 -2
- package/web-ui/partials/index/panel-sessions.html +4 -2
- package/web-ui/partials/index/panel-usage.html +7 -0
- package/web-ui/styles/controls-forms.css +49 -2
- package/web-ui/styles/layout-shell.css +1 -0
- package/web-ui/styles/responsive.css +0 -2
- package/web-ui/styles/sessions-list.css +2 -4
- package/web-ui/styles/sessions-toolbar-trash.css +4 -4
- package/web-ui/styles/sessions-usage.css +24 -0
- /package/{res → web-ui/res}/json5.min.js +0 -0
- /package/{res → web-ui/res}/logo-pack.webp +0 -0
- /package/{res → web-ui/res}/vue.global.prod.js +0 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const http = require('http');
|
|
4
|
+
const https = require('https');
|
|
5
|
+
const net = require('net');
|
|
6
|
+
|
|
7
|
+
function isPlainObject(value) {
|
|
8
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function cloneJson(value, fallback) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(JSON.stringify(value));
|
|
14
|
+
} catch (_) {
|
|
15
|
+
return fallback;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizeText(value, maxLength = 4000) {
|
|
20
|
+
const text = value === undefined || value === null ? '' : String(value).trim();
|
|
21
|
+
if (!text) return '';
|
|
22
|
+
return text.length > maxLength ? text.slice(0, maxLength) : text;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function uniqueStringList(items = []) {
|
|
26
|
+
const list = Array.isArray(items) ? items : [];
|
|
27
|
+
const out = [];
|
|
28
|
+
const seen = new Set();
|
|
29
|
+
for (const item of list) {
|
|
30
|
+
const text = normalizeText(item, 200);
|
|
31
|
+
if (!text || seen.has(text)) continue;
|
|
32
|
+
seen.add(text);
|
|
33
|
+
out.push(text);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function expandEnvTemplate(value, env = process.env) {
|
|
39
|
+
const text = String(value || '');
|
|
40
|
+
if (!text) return '';
|
|
41
|
+
return text.replace(/\$\{([A-Z0-9_]+)\}/g, (_, key) => {
|
|
42
|
+
const envValue = env && typeof env[key] === 'string' ? env[key] : '';
|
|
43
|
+
return envValue ? envValue : '';
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isPrivateNetworkHost(hostname) {
|
|
48
|
+
const host = typeof hostname === 'string' ? hostname.trim().toLowerCase() : '';
|
|
49
|
+
if (!host) return true;
|
|
50
|
+
if (host === 'localhost') return true;
|
|
51
|
+
const ipVer = net.isIP(host);
|
|
52
|
+
if (!ipVer) return false;
|
|
53
|
+
if (ipVer === 4) {
|
|
54
|
+
const parts = host.split('.').map((x) => parseInt(x, 10));
|
|
55
|
+
if (parts.length !== 4 || parts.some((x) => !Number.isFinite(x))) return true;
|
|
56
|
+
const [a, b] = parts;
|
|
57
|
+
if (a === 10) return true;
|
|
58
|
+
if (a === 127) return true;
|
|
59
|
+
if (a === 169 && b === 254) return true;
|
|
60
|
+
if (a === 192 && b === 168) return true;
|
|
61
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (ipVer === 6) {
|
|
65
|
+
if (host === '::1') return true;
|
|
66
|
+
if (host.startsWith('fe80:')) return true;
|
|
67
|
+
if (host.startsWith('fc') || host.startsWith('fd')) return true;
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function readAutomationConfig(configPath, options = {}) {
|
|
74
|
+
const filePath = typeof configPath === 'string' ? configPath.trim() : '';
|
|
75
|
+
if (!filePath) {
|
|
76
|
+
return { ok: true, exists: false, config: createDefaultAutomationConfig() };
|
|
77
|
+
}
|
|
78
|
+
if (!fs.existsSync(filePath)) {
|
|
79
|
+
return { ok: true, exists: false, config: createDefaultAutomationConfig() };
|
|
80
|
+
}
|
|
81
|
+
let raw = '';
|
|
82
|
+
try {
|
|
83
|
+
raw = fs.readFileSync(filePath, 'utf-8');
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return { ok: false, error: error && error.message ? error.message : 'failed to read automation config', exists: true };
|
|
86
|
+
}
|
|
87
|
+
let parsed;
|
|
88
|
+
try {
|
|
89
|
+
parsed = JSON.parse(raw);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return { ok: false, error: error && error.message ? error.message : 'invalid automation config json', exists: true };
|
|
92
|
+
}
|
|
93
|
+
const normalized = normalizeAutomationConfig(parsed, options);
|
|
94
|
+
return { ok: true, exists: true, config: normalized };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function createDefaultAutomationConfig() {
|
|
98
|
+
return {
|
|
99
|
+
version: 1,
|
|
100
|
+
rules: [],
|
|
101
|
+
schedules: [],
|
|
102
|
+
notifiers: []
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function normalizeAutomationRule(rule = {}) {
|
|
107
|
+
const item = isPlainObject(rule) ? rule : {};
|
|
108
|
+
return {
|
|
109
|
+
id: normalizeText(item.id, 120),
|
|
110
|
+
enabled: item.enabled !== false,
|
|
111
|
+
source: normalizeText(item.source, 40).toLowerCase(),
|
|
112
|
+
event: normalizeText(item.event, 120).toLowerCase(),
|
|
113
|
+
action: cloneJson(isPlainObject(item.action) ? item.action : {}, {})
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function normalizeAutomationSchedule(schedule = {}) {
|
|
118
|
+
const item = isPlainObject(schedule) ? schedule : {};
|
|
119
|
+
return {
|
|
120
|
+
id: normalizeText(item.id, 120),
|
|
121
|
+
enabled: item.enabled !== false,
|
|
122
|
+
cron: normalizeText(item.cron, 120),
|
|
123
|
+
action: cloneJson(isPlainObject(item.action) ? item.action : {}, {})
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function normalizeAutomationNotifier(notifier = {}, options = {}) {
|
|
128
|
+
const item = isPlainObject(notifier) ? notifier : {};
|
|
129
|
+
const env = options.env || process.env;
|
|
130
|
+
const url = normalizeText(item.url, 800);
|
|
131
|
+
const normalizedUrl = url ? expandEnvTemplate(url, env) : '';
|
|
132
|
+
return {
|
|
133
|
+
id: normalizeText(item.id, 120),
|
|
134
|
+
enabled: item.enabled !== false,
|
|
135
|
+
type: normalizeText(item.type, 40).toLowerCase(),
|
|
136
|
+
url: normalizedUrl,
|
|
137
|
+
events: uniqueStringList(item.events || []).map((value) => value.toLowerCase()),
|
|
138
|
+
headers: cloneJson(isPlainObject(item.headers) ? item.headers : {}, {})
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function normalizeAutomationConfig(config = {}, options = {}) {
|
|
143
|
+
const base = isPlainObject(config) ? config : {};
|
|
144
|
+
const defaults = createDefaultAutomationConfig();
|
|
145
|
+
const rawRules = Array.isArray(base.rules) ? base.rules : [];
|
|
146
|
+
const rawSchedules = Array.isArray(base.schedules) ? base.schedules : [];
|
|
147
|
+
const rawNotifiers = Array.isArray(base.notifiers) ? base.notifiers : [];
|
|
148
|
+
return {
|
|
149
|
+
version: Number.isFinite(base.version) ? base.version : defaults.version,
|
|
150
|
+
rules: rawRules.map(normalizeAutomationRule).filter((rule) => rule.id && rule.source && rule.event),
|
|
151
|
+
schedules: rawSchedules.map(normalizeAutomationSchedule).filter((item) => item.id && item.cron),
|
|
152
|
+
notifiers: rawNotifiers.map((item) => normalizeAutomationNotifier(item, options)).filter((item) => item.id && item.type)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function matchAutomationRule(config = {}, event = {}) {
|
|
157
|
+
const cfg = isPlainObject(config) ? config : createDefaultAutomationConfig();
|
|
158
|
+
const source = normalizeText(event.source, 40).toLowerCase();
|
|
159
|
+
const eventKey = normalizeText(event.event, 120).toLowerCase();
|
|
160
|
+
if (!source || !eventKey) return null;
|
|
161
|
+
const rules = Array.isArray(cfg.rules) ? cfg.rules : [];
|
|
162
|
+
for (const rule of rules) {
|
|
163
|
+
if (!rule || rule.enabled === false) continue;
|
|
164
|
+
if (rule.source !== source) continue;
|
|
165
|
+
const pattern = rule.event;
|
|
166
|
+
if (!pattern) continue;
|
|
167
|
+
if (pattern.endsWith('*')) {
|
|
168
|
+
const prefix = pattern.slice(0, -1);
|
|
169
|
+
if (eventKey.startsWith(prefix)) return rule;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (pattern === eventKey) return rule;
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function buildAutomationEventKey(source, headers = {}, payload = {}) {
|
|
178
|
+
const src = normalizeText(source, 40).toLowerCase();
|
|
179
|
+
const hdr = isPlainObject(headers) ? headers : {};
|
|
180
|
+
const body = isPlainObject(payload) ? payload : {};
|
|
181
|
+
if (!src) return '';
|
|
182
|
+
|
|
183
|
+
if (src === 'github') {
|
|
184
|
+
const eventName = normalizeText(hdr['x-github-event'] || hdr['X-GitHub-Event'], 80).toLowerCase();
|
|
185
|
+
const action = normalizeText(body.action, 80).toLowerCase();
|
|
186
|
+
if (!eventName) return '';
|
|
187
|
+
return action ? `${eventName}.${action}` : eventName;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (src === 'gitlab') {
|
|
191
|
+
const eventName = normalizeText(hdr['x-gitlab-event'] || hdr['X-Gitlab-Event'], 120).toLowerCase();
|
|
192
|
+
const kind = normalizeText(body.object_kind || body.event_type, 120).toLowerCase();
|
|
193
|
+
const action = normalizeText(body.action, 80).toLowerCase();
|
|
194
|
+
const base = kind || eventName;
|
|
195
|
+
if (!base) return '';
|
|
196
|
+
return action ? `${base}.${action}` : base;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const fallback = normalizeText(
|
|
200
|
+
hdr['x-event'] || hdr['X-Event'] || hdr['x-codexmate-event'] || hdr['X-Codexmate-Event'],
|
|
201
|
+
120
|
|
202
|
+
).toLowerCase();
|
|
203
|
+
return fallback;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function httpPostJson(url, payload, headers = {}, options = {}) {
|
|
207
|
+
const target = normalizeText(url, 800);
|
|
208
|
+
if (!target) {
|
|
209
|
+
return Promise.resolve({ ok: false, error: 'url is required' });
|
|
210
|
+
}
|
|
211
|
+
let parsed;
|
|
212
|
+
try {
|
|
213
|
+
parsed = new URL(target);
|
|
214
|
+
} catch (_) {
|
|
215
|
+
return Promise.resolve({ ok: false, error: 'invalid url' });
|
|
216
|
+
}
|
|
217
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
218
|
+
return Promise.resolve({ ok: false, error: 'invalid url protocol' });
|
|
219
|
+
}
|
|
220
|
+
const allowPrivate = process.env.CODEXMATE_ALLOW_AUTOMATION_PRIVATE_NETWORK === '1';
|
|
221
|
+
if (!allowPrivate && isPrivateNetworkHost(parsed.hostname || '')) {
|
|
222
|
+
return Promise.resolve({ ok: false, error: 'refusing to post to private network url' });
|
|
223
|
+
}
|
|
224
|
+
const transport = parsed.protocol === 'http:' ? http : https;
|
|
225
|
+
const data = Buffer.from(JSON.stringify(payload || {}), 'utf-8');
|
|
226
|
+
const timeoutMs = Number.isFinite(options.timeoutMs) ? Math.max(200, Math.floor(options.timeoutMs)) : 4000;
|
|
227
|
+
const requestOptions = {
|
|
228
|
+
method: 'POST',
|
|
229
|
+
hostname: parsed.hostname,
|
|
230
|
+
port: parsed.port || (parsed.protocol === 'http:' ? 80 : 443),
|
|
231
|
+
path: `${parsed.pathname || '/'}${parsed.search || ''}`,
|
|
232
|
+
headers: {
|
|
233
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
234
|
+
'Content-Length': data.length,
|
|
235
|
+
...headers
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
return new Promise((resolve) => {
|
|
239
|
+
const req = transport.request(requestOptions, (res) => {
|
|
240
|
+
let body = '';
|
|
241
|
+
res.setEncoding('utf-8');
|
|
242
|
+
res.on('data', (chunk) => body += chunk);
|
|
243
|
+
res.on('end', () => {
|
|
244
|
+
resolve({
|
|
245
|
+
ok: (res.statusCode || 0) >= 200 && (res.statusCode || 0) < 300,
|
|
246
|
+
statusCode: res.statusCode || 0,
|
|
247
|
+
body: body.slice(0, 2000)
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
req.on('error', (error) => {
|
|
252
|
+
resolve({ ok: false, error: error && error.message ? error.message : 'request failed' });
|
|
253
|
+
});
|
|
254
|
+
req.setTimeout(timeoutMs, () => {
|
|
255
|
+
req.destroy(new Error('timeout'));
|
|
256
|
+
});
|
|
257
|
+
req.write(data);
|
|
258
|
+
req.end();
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function parseCronPart(part, min, max) {
|
|
263
|
+
const text = normalizeText(part, 120);
|
|
264
|
+
if (!text) return null;
|
|
265
|
+
if (text === '*') return { any: true };
|
|
266
|
+
if (text.startsWith('*/')) {
|
|
267
|
+
const step = Number.parseInt(text.slice(2), 10);
|
|
268
|
+
if (!Number.isFinite(step) || step <= 0) return null;
|
|
269
|
+
return { step };
|
|
270
|
+
}
|
|
271
|
+
const list = text.split(',').map((chunk) => chunk.trim()).filter(Boolean);
|
|
272
|
+
if (list.length === 0) return null;
|
|
273
|
+
const ranges = [];
|
|
274
|
+
for (const item of list) {
|
|
275
|
+
if (item.includes('-')) {
|
|
276
|
+
const [rawStart, rawEnd] = item.split('-', 2);
|
|
277
|
+
const start = Number.parseInt(rawStart, 10);
|
|
278
|
+
const end = Number.parseInt(rawEnd, 10);
|
|
279
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) return null;
|
|
280
|
+
ranges.push({ start, end });
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const value = Number.parseInt(item, 10);
|
|
284
|
+
if (!Number.isFinite(value)) return null;
|
|
285
|
+
ranges.push({ start: value, end: value });
|
|
286
|
+
}
|
|
287
|
+
return { ranges, min, max };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function cronPartMatches(spec, value) {
|
|
291
|
+
if (!spec) return false;
|
|
292
|
+
if (spec.any) return true;
|
|
293
|
+
if (spec.step) {
|
|
294
|
+
return value % spec.step === 0;
|
|
295
|
+
}
|
|
296
|
+
const ranges = Array.isArray(spec.ranges) ? spec.ranges : [];
|
|
297
|
+
for (const range of ranges) {
|
|
298
|
+
const start = Number.isFinite(range.start) ? range.start : NaN;
|
|
299
|
+
const end = Number.isFinite(range.end) ? range.end : NaN;
|
|
300
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
|
|
301
|
+
const normalizedStart = Math.min(start, end);
|
|
302
|
+
const normalizedEnd = Math.max(start, end);
|
|
303
|
+
if (value >= normalizedStart && value <= normalizedEnd) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function isCronMatch(expr, date = new Date()) {
|
|
311
|
+
const text = normalizeText(expr, 120);
|
|
312
|
+
if (!text) return false;
|
|
313
|
+
const parts = text.split(/\s+/g).filter(Boolean);
|
|
314
|
+
if (parts.length !== 5) return false;
|
|
315
|
+
const [minExpr, hourExpr, domExpr, monExpr, dowExpr] = parts;
|
|
316
|
+
const minute = date.getMinutes();
|
|
317
|
+
const hour = date.getHours();
|
|
318
|
+
const dom = date.getDate();
|
|
319
|
+
const month = date.getMonth() + 1;
|
|
320
|
+
const dow = date.getDay();
|
|
321
|
+
const minSpec = parseCronPart(minExpr, 0, 59);
|
|
322
|
+
const hourSpec = parseCronPart(hourExpr, 0, 23);
|
|
323
|
+
const domSpec = parseCronPart(domExpr, 1, 31);
|
|
324
|
+
const monSpec = parseCronPart(monExpr, 1, 12);
|
|
325
|
+
const dowSpecRaw = parseCronPart(dowExpr, 0, 7);
|
|
326
|
+
const dowValue = dow;
|
|
327
|
+
if (!minSpec || !hourSpec || !domSpec || !monSpec || !dowSpecRaw) return false;
|
|
328
|
+
const dowSpec = dowSpecRaw.step || dowSpecRaw.any ? dowSpecRaw : {
|
|
329
|
+
...dowSpecRaw,
|
|
330
|
+
ranges: (dowSpecRaw.ranges || []).map((range) => ({
|
|
331
|
+
start: range.start === 7 ? 0 : range.start,
|
|
332
|
+
end: range.end === 7 ? 0 : range.end
|
|
333
|
+
}))
|
|
334
|
+
};
|
|
335
|
+
return cronPartMatches(minSpec, minute)
|
|
336
|
+
&& cronPartMatches(hourSpec, hour)
|
|
337
|
+
&& cronPartMatches(domSpec, dom)
|
|
338
|
+
&& cronPartMatches(monSpec, month)
|
|
339
|
+
&& cronPartMatches(dowSpec, dowValue);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function formatTaskRunNotificationPayload(detail = {}) {
|
|
343
|
+
const base = isPlainObject(detail) ? detail : {};
|
|
344
|
+
const run = isPlainObject(base.run) ? base.run : {};
|
|
345
|
+
const nodes = Array.isArray(run.nodes) ? run.nodes : [];
|
|
346
|
+
return {
|
|
347
|
+
kind: 'task-run',
|
|
348
|
+
runId: base.runId || '',
|
|
349
|
+
taskId: base.taskId || '',
|
|
350
|
+
title: base.title || '',
|
|
351
|
+
target: base.target || '',
|
|
352
|
+
engine: base.engine || '',
|
|
353
|
+
allowWrite: base.allowWrite === true,
|
|
354
|
+
dryRun: base.dryRun === true,
|
|
355
|
+
status: run.status || base.status || '',
|
|
356
|
+
startedAt: run.startedAt || base.startedAt || '',
|
|
357
|
+
endedAt: run.endedAt || base.endedAt || '',
|
|
358
|
+
durationMs: run.durationMs || 0,
|
|
359
|
+
summary: run.summary || base.summary || '',
|
|
360
|
+
error: run.error || base.error || '',
|
|
361
|
+
nodes: nodes.map((node) => ({
|
|
362
|
+
id: node.id || '',
|
|
363
|
+
kind: node.kind || '',
|
|
364
|
+
status: node.status || '',
|
|
365
|
+
attemptCount: node.attemptCount || 0,
|
|
366
|
+
summary: node.summary || '',
|
|
367
|
+
error: node.error || ''
|
|
368
|
+
}))
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
async function dispatchAutomationNotifiers(config, eventType, payload) {
|
|
373
|
+
const cfg = isPlainObject(config) ? config : createDefaultAutomationConfig();
|
|
374
|
+
const normalizedEvent = normalizeText(eventType, 80).toLowerCase();
|
|
375
|
+
if (!normalizedEvent) return [];
|
|
376
|
+
const out = [];
|
|
377
|
+
const notifiers = Array.isArray(cfg.notifiers) ? cfg.notifiers : [];
|
|
378
|
+
for (const notifier of notifiers) {
|
|
379
|
+
if (!notifier || notifier.enabled === false) continue;
|
|
380
|
+
const events = Array.isArray(notifier.events) ? notifier.events : [];
|
|
381
|
+
if (events.length > 0 && !events.includes(normalizedEvent)) {
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (notifier.type === 'webhook') {
|
|
385
|
+
out.push({
|
|
386
|
+
id: notifier.id,
|
|
387
|
+
type: notifier.type,
|
|
388
|
+
...(await httpPostJson(notifier.url, payload, notifier.headers || {}))
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return out;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
module.exports = {
|
|
396
|
+
createDefaultAutomationConfig,
|
|
397
|
+
normalizeAutomationConfig,
|
|
398
|
+
readAutomationConfig,
|
|
399
|
+
matchAutomationRule,
|
|
400
|
+
buildAutomationEventKey,
|
|
401
|
+
isCronMatch,
|
|
402
|
+
dispatchAutomationNotifiers,
|
|
403
|
+
formatTaskRunNotificationPayload
|
|
404
|
+
};
|
package/lib/cli-path-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const {
|
|
3
|
+
const { spawnSync } = require('child_process');
|
|
4
4
|
|
|
5
5
|
function normalizePathForCompare(targetPath, options = {}) {
|
|
6
6
|
const ignoreCase = !!options.ignoreCase;
|
|
@@ -52,10 +52,27 @@ function resolveCopyTargetRoot(targetDir) {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
function commandExists(command, args = '') {
|
|
55
|
+
const cmd = typeof command === 'string' ? command.trim() : '';
|
|
56
|
+
const argText = typeof args === 'string' ? args.trim() : '';
|
|
57
|
+
if (!cmd || cmd.includes('\0') || /[\r\n]/.test(cmd)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const argv = argText ? argText.split(/\s+/g).filter(Boolean) : [];
|
|
61
|
+
const hasSeparators = cmd.includes('/') || cmd.includes('\\');
|
|
62
|
+
const useShell = process.platform === 'win32' && !hasSeparators;
|
|
63
|
+
if (useShell) {
|
|
64
|
+
if (!/^[A-Za-z0-9._-]+$/.test(cmd)) return false;
|
|
65
|
+
if (argText && /[\r\n;&|<>`$]/.test(argText)) return false;
|
|
66
|
+
}
|
|
55
67
|
try {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
68
|
+
const probe = spawnSync(cmd, argv, {
|
|
69
|
+
stdio: 'ignore',
|
|
70
|
+
windowsHide: true,
|
|
71
|
+
timeout: 5000,
|
|
72
|
+
shell: useShell
|
|
73
|
+
});
|
|
74
|
+
return probe.status === 0;
|
|
75
|
+
} catch (_) {
|
|
59
76
|
return false;
|
|
60
77
|
}
|
|
61
78
|
}
|
|
@@ -66,4 +83,3 @@ module.exports = {
|
|
|
66
83
|
resolveCopyTargetRoot,
|
|
67
84
|
commandExists
|
|
68
85
|
};
|
|
69
|
-
|
package/lib/cli-sessions.js
CHANGED
|
@@ -38,7 +38,25 @@ function isBootstrapLikeText(text) {
|
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
if (normalized.length < 80) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
let hits = 0;
|
|
45
|
+
for (const marker of BOOTSTRAP_TEXT_MARKERS) {
|
|
46
|
+
if (normalized.includes(marker)) {
|
|
47
|
+
hits += 1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (hits >= 2) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if (normalized.includes('<environment_context>')) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (normalized.includes('agents.md instructions')) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
42
60
|
}
|
|
43
61
|
|
|
44
62
|
function removeLeadingSystemMessage(messages) {
|
|
@@ -164,6 +182,18 @@ function extractMessageFromRecord(record, source) {
|
|
|
164
182
|
}
|
|
165
183
|
return null;
|
|
166
184
|
}
|
|
185
|
+
if (source === 'codebuddy') {
|
|
186
|
+
if (record.type === 'message') {
|
|
187
|
+
const role = normalizeRole(record.role);
|
|
188
|
+
const content = record.message ? record.message.content : record.content;
|
|
189
|
+
const text = extractMessageText(content);
|
|
190
|
+
if (!role || !text) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
return { role, text };
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
167
197
|
|
|
168
198
|
const role = normalizeRole(record.type);
|
|
169
199
|
if (!role) {
|
|
@@ -300,6 +330,7 @@ function extractSessionDetailPreviewFromTailText(text, source, messageLimit) {
|
|
|
300
330
|
});
|
|
301
331
|
}
|
|
302
332
|
|
|
333
|
+
state.messages = removeLeadingSystemMessage(state.messages);
|
|
303
334
|
return state;
|
|
304
335
|
}
|
|
305
336
|
|
|
@@ -3,6 +3,7 @@ const path = require('path');
|
|
|
3
3
|
const crypto = require('crypto');
|
|
4
4
|
|
|
5
5
|
const DEFAULT_DOWNLOAD_ARTIFACT_TTL_MS = 10 * 60 * 1000;
|
|
6
|
+
const MAX_DOWNLOAD_ARTIFACTS = 200;
|
|
6
7
|
const g_downloadArtifacts = new Map();
|
|
7
8
|
|
|
8
9
|
function registerDownloadArtifact(filePath, options = {}) {
|
|
@@ -23,7 +24,19 @@ function registerDownloadArtifact(filePath, options = {}) {
|
|
|
23
24
|
expiresAt
|
|
24
25
|
});
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
while (g_downloadArtifacts.size > MAX_DOWNLOAD_ARTIFACTS) {
|
|
28
|
+
const firstKey = g_downloadArtifacts.keys().next().value;
|
|
29
|
+
if (!firstKey) break;
|
|
30
|
+
const evicted = g_downloadArtifacts.get(firstKey);
|
|
31
|
+
g_downloadArtifacts.delete(firstKey);
|
|
32
|
+
if (evicted && evicted.deleteAfterDownload && evicted.filePath && fs.existsSync(evicted.filePath)) {
|
|
33
|
+
try {
|
|
34
|
+
fs.unlinkSync(evicted.filePath);
|
|
35
|
+
} catch (_) {}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const timer = setTimeout(() => {
|
|
27
40
|
const artifact = g_downloadArtifacts.get(token);
|
|
28
41
|
if (!artifact) return;
|
|
29
42
|
if (Date.now() < artifact.expiresAt) return;
|
|
@@ -34,6 +47,9 @@ function registerDownloadArtifact(filePath, options = {}) {
|
|
|
34
47
|
} catch (_) {}
|
|
35
48
|
}
|
|
36
49
|
}, ttlMs + 2000);
|
|
50
|
+
if (timer && typeof timer.unref === 'function') {
|
|
51
|
+
timer.unref();
|
|
52
|
+
}
|
|
37
53
|
|
|
38
54
|
return {
|
|
39
55
|
token,
|
|
@@ -74,4 +90,3 @@ module.exports = {
|
|
|
74
90
|
registerDownloadArtifact,
|
|
75
91
|
resolveDownloadArtifact
|
|
76
92
|
};
|
|
77
|
-
|
package/lib/mcp-stdio.js
CHANGED
|
@@ -280,6 +280,9 @@ function createMcpStdioServer(options = {}) {
|
|
|
280
280
|
const stdout = options.stdout || process.stdout;
|
|
281
281
|
const router = createMcpRequestRouter(options);
|
|
282
282
|
const jsonRpcVersion = '2.0';
|
|
283
|
+
const maxFrameBytes = Number.isFinite(options.maxFrameBytes) && options.maxFrameBytes > 0
|
|
284
|
+
? Math.floor(options.maxFrameBytes)
|
|
285
|
+
: 16 * 1024 * 1024;
|
|
283
286
|
|
|
284
287
|
let buffer = Buffer.alloc(0);
|
|
285
288
|
let started = false;
|
|
@@ -379,6 +382,11 @@ function createMcpStdioServer(options = {}) {
|
|
|
379
382
|
writeError(null, jsonRpcError(-32600, 'Invalid Content-Length header'));
|
|
380
383
|
return;
|
|
381
384
|
}
|
|
385
|
+
if (length > maxFrameBytes) {
|
|
386
|
+
buffer = Buffer.alloc(0);
|
|
387
|
+
writeError(null, jsonRpcError(-32600, 'Content-Length too large'));
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
382
390
|
|
|
383
391
|
const bodyOffset = headerEnd + 4;
|
|
384
392
|
const frameLength = bodyOffset + length;
|
|
@@ -394,6 +402,11 @@ function createMcpStdioServer(options = {}) {
|
|
|
394
402
|
|
|
395
403
|
const onData = async (chunk) => {
|
|
396
404
|
if (stopped) return;
|
|
405
|
+
if (chunk && (buffer.length + chunk.length) > (maxFrameBytes + 64 * 1024)) {
|
|
406
|
+
buffer = Buffer.alloc(0);
|
|
407
|
+
writeError(null, jsonRpcError(-32600, 'Frame too large'));
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
397
410
|
buffer = buffer.length === 0 ? chunk : Buffer.concat([buffer, chunk]);
|
|
398
411
|
try {
|
|
399
412
|
await parseBuffer();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexmate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "Codex/Claude Code/OpenClaw 配置、会话与任务编排 CLI + Web 工具",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
"web-ui.html",
|
|
14
14
|
"lib/",
|
|
15
15
|
"web-ui/",
|
|
16
|
-
"res/json5.min.js",
|
|
17
|
-
"res/vue.global.prod.js",
|
|
18
|
-
"res/logo-pack.webp",
|
|
19
16
|
"doc/",
|
|
20
17
|
"README.md",
|
|
21
18
|
"README.zh.md",
|
|
@@ -25,7 +22,7 @@
|
|
|
25
22
|
".": "./cli.js",
|
|
26
23
|
"./lib/*": "./lib/*.js",
|
|
27
24
|
"./web-ui/*": "./web-ui/*",
|
|
28
|
-
"./res/*": "./res/*"
|
|
25
|
+
"./res/*": "./web-ui/res/*"
|
|
29
26
|
},
|
|
30
27
|
"scripts": {
|
|
31
28
|
"dev": "node cli.js run",
|
package/web-ui/app.js
CHANGED
|
@@ -178,17 +178,20 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
178
178
|
sessionPathOptionsMap: {
|
|
179
179
|
all: [],
|
|
180
180
|
codex: [],
|
|
181
|
-
claude: []
|
|
181
|
+
claude: [],
|
|
182
|
+
gemini: []
|
|
182
183
|
},
|
|
183
184
|
sessionPathOptionsLoadedMap: {
|
|
184
185
|
all: false,
|
|
185
186
|
codex: false,
|
|
186
|
-
claude: false
|
|
187
|
+
claude: false,
|
|
188
|
+
gemini: false
|
|
187
189
|
},
|
|
188
190
|
sessionPathRequestSeqMap: {
|
|
189
191
|
all: 0,
|
|
190
192
|
codex: 0,
|
|
191
|
-
claude: 0
|
|
193
|
+
claude: 0,
|
|
194
|
+
gemini: 0
|
|
192
195
|
},
|
|
193
196
|
sessionExporting: {},
|
|
194
197
|
sessionCloning: {},
|
|
@@ -29,14 +29,14 @@ function shouldUseFastSessionBrowseLimit(options = {}) {
|
|
|
29
29
|
|
|
30
30
|
export function isSessionQueryEnabled(source) {
|
|
31
31
|
const normalized = normalizeSessionSource(source, '');
|
|
32
|
-
return normalized === 'codex' || normalized === 'claude' || normalized === 'all';
|
|
32
|
+
return normalized === 'codex' || normalized === 'claude' || normalized === 'gemini' || normalized === 'codebuddy' || normalized === 'all';
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function normalizeSessionSource(source, fallback = 'all') {
|
|
36
36
|
const normalized = typeof source === 'string'
|
|
37
37
|
? source.trim().toLowerCase()
|
|
38
38
|
: '';
|
|
39
|
-
if (normalized === 'codex' || normalized === 'claude' || normalized === 'all') {
|
|
39
|
+
if (normalized === 'codex' || normalized === 'claude' || normalized === 'gemini' || normalized === 'codebuddy' || normalized === 'all') {
|
|
40
40
|
return normalized;
|
|
41
41
|
}
|
|
42
42
|
return fallback;
|
|
@@ -77,6 +77,8 @@ export function createDashboardComputed() {
|
|
|
77
77
|
inspectorSessionSourceLabel() {
|
|
78
78
|
if (this.sessionFilterSource === 'codex') return this.t('dashboard.sessionSource.codex');
|
|
79
79
|
if (this.sessionFilterSource === 'claude') return this.t('dashboard.sessionSource.claude');
|
|
80
|
+
if (this.sessionFilterSource === 'gemini') return this.t('dashboard.sessionSource.gemini');
|
|
81
|
+
if (this.sessionFilterSource === 'codebuddy') return this.t('dashboard.sessionSource.codebuddy');
|
|
80
82
|
return this.t('dashboard.sessionSource.all');
|
|
81
83
|
},
|
|
82
84
|
inspectorSessionPathLabel() {
|
|
@@ -549,6 +549,23 @@ export function createSessionComputed() {
|
|
|
549
549
|
];
|
|
550
550
|
},
|
|
551
551
|
|
|
552
|
+
usageCurrentSessionStats() {
|
|
553
|
+
const summary = this.sessionUsageCharts && this.sessionUsageCharts.summary
|
|
554
|
+
? this.sessionUsageCharts.summary
|
|
555
|
+
: null;
|
|
556
|
+
if (!summary) return null;
|
|
557
|
+
const t = typeof this.t === 'function' ? this.t : null;
|
|
558
|
+
return {
|
|
559
|
+
apiDurationLabel: formatUsageDuration(summary.activeDurationMs || 0, { compact: true, lang: this.lang }),
|
|
560
|
+
totalDurationLabel: formatUsageDuration(summary.totalDurationMs || 0, { compact: true, lang: this.lang }),
|
|
561
|
+
tokenLabel: formatCompactUsageSummaryNumber(summary.totalTokens || 0),
|
|
562
|
+
label: t ? t('usage.currentSession.title') : '当前会话',
|
|
563
|
+
apiDurationText: t ? t('usage.currentSession.apiDuration') : 'API时长',
|
|
564
|
+
totalDurationText: t ? t('usage.currentSession.totalDuration') : '总时长',
|
|
565
|
+
tokenText: t ? t('usage.currentSession.tokens') : 'Token'
|
|
566
|
+
};
|
|
567
|
+
},
|
|
568
|
+
|
|
552
569
|
sessionUsageDaily() {
|
|
553
570
|
const baseBuckets = this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.buckets)
|
|
554
571
|
? this.sessionUsageCharts.buckets
|