codexmate 0.0.23 → 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 +32 -9
- package/README.zh.md +33 -9
- package/cli/auth-profiles.js +23 -7
- package/cli/builtin-proxy.js +35 -0
- package/cli/claude-proxy.js +24 -0
- package/cli/doctor-core.js +903 -0
- package/cli/import-skills-url.js +356 -0
- package/cli/openai-bridge.js +51 -4
- package/cli/session-usage.js +8 -2
- package/cli.js +1921 -399
- package/lib/automation.js +404 -0
- package/lib/cli-models-utils.js +0 -40
- package/lib/cli-network-utils.js +28 -2
- 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 +3 -3
- package/plugins/README.md +20 -0
- package/plugins/README.zh-CN.md +20 -0
- package/plugins/prompt-templates/comment-polish/index.mjs +25 -0
- package/plugins/prompt-templates/computed.mjs +253 -0
- package/plugins/prompt-templates/index.mjs +8 -0
- package/plugins/prompt-templates/manifest.mjs +15 -0
- package/plugins/prompt-templates/methods.mjs +619 -0
- package/plugins/prompt-templates/overview.mjs +90 -0
- package/plugins/prompt-templates/ownership.mjs +19 -0
- package/plugins/prompt-templates/rule-ack/index.mjs +21 -0
- package/plugins/prompt-templates/storage.mjs +64 -0
- package/plugins/registry.mjs +16 -0
- package/web-ui/app.js +21 -35
- package/web-ui/index.html +4 -3
- package/web-ui/logic.sessions.mjs +2 -2
- package/web-ui/modules/app.computed.dashboard.mjs +24 -22
- package/web-ui/modules/app.computed.main-tabs.mjs +3 -0
- package/web-ui/modules/app.computed.session.mjs +17 -0
- package/web-ui/modules/app.methods.agents.mjs +91 -3
- package/web-ui/modules/app.methods.codex-config.mjs +153 -164
- package/web-ui/modules/app.methods.install.mjs +28 -0
- package/web-ui/modules/app.methods.navigation.mjs +34 -1
- package/web-ui/modules/app.methods.runtime.mjs +24 -2
- package/web-ui/modules/app.methods.session-actions.mjs +8 -1
- package/web-ui/modules/app.methods.session-browser.mjs +37 -6
- package/web-ui/modules/app.methods.session-trash.mjs +4 -2
- package/web-ui/modules/config-mode.computed.mjs +1 -3
- package/web-ui/modules/i18n.dict.mjs +2055 -0
- package/web-ui/modules/i18n.mjs +2 -1769
- package/web-ui/partials/index/layout-header.html +48 -34
- package/web-ui/partials/index/modal-config-template-agents.html +3 -4
- package/web-ui/partials/index/modal-health-check.html +33 -60
- package/web-ui/partials/index/panel-config-claude.html +35 -15
- package/web-ui/partials/index/panel-config-codex.html +47 -19
- package/web-ui/partials/index/panel-config-openclaw.html +8 -3
- package/web-ui/partials/index/panel-dashboard.html +186 -0
- package/web-ui/partials/index/panel-docs.html +1 -1
- package/web-ui/partials/index/panel-market.html +3 -0
- package/web-ui/partials/index/panel-orchestration.html +3 -0
- package/web-ui/partials/index/panel-plugins.html +16 -10
- package/web-ui/partials/index/panel-sessions.html +8 -3
- package/web-ui/partials/index/panel-settings.html +1 -1
- package/web-ui/partials/index/panel-usage.html +9 -1
- package/web-ui/res/logo-pack.webp +0 -0
- package/web-ui/styles/controls-forms.css +58 -4
- package/web-ui/styles/dashboard.css +274 -0
- package/web-ui/styles/layout-shell.css +3 -2
- package/web-ui/styles/responsive.css +0 -2
- package/web-ui/styles/sessions-list.css +5 -7
- package/web-ui/styles/sessions-toolbar-trash.css +4 -4
- package/web-ui/styles/sessions-usage.css +33 -0
- package/web-ui/styles.css +1 -0
- package/res/logo.png +0 -0
- /package/{res → web-ui/res}/json5.min.js +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-models-utils.js
CHANGED
|
@@ -271,45 +271,6 @@ function buildModelProbeSpec(provider, modelName, baseUrl) {
|
|
|
271
271
|
return buildModelProbeSpecs(provider, modelName, baseUrl)[0] || null;
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
function buildModelConversationSpecs(provider, modelName, baseUrl, prompt, options = {}) {
|
|
275
|
-
const model = typeof modelName === 'string' ? modelName.trim() : '';
|
|
276
|
-
const userPrompt = typeof prompt === 'string' ? prompt.trim() : '';
|
|
277
|
-
if (!model || !userPrompt) return [];
|
|
278
|
-
|
|
279
|
-
const wireApi = normalizeWireApi(provider && provider.wire_api);
|
|
280
|
-
const maxOutputTokens = Number.isFinite(options.maxOutputTokens)
|
|
281
|
-
? Math.max(1, Number(options.maxOutputTokens))
|
|
282
|
-
: 256;
|
|
283
|
-
let pathSuffix = 'responses';
|
|
284
|
-
let body = {
|
|
285
|
-
model,
|
|
286
|
-
input: userPrompt,
|
|
287
|
-
max_output_tokens: maxOutputTokens
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
if (wireApi === 'chat_completions' || wireApi === 'chat') {
|
|
291
|
-
pathSuffix = 'chat/completions';
|
|
292
|
-
body = {
|
|
293
|
-
model,
|
|
294
|
-
messages: [{ role: 'user', content: userPrompt }],
|
|
295
|
-
max_tokens: maxOutputTokens
|
|
296
|
-
};
|
|
297
|
-
} else if (wireApi === 'completions') {
|
|
298
|
-
pathSuffix = 'completions';
|
|
299
|
-
body = {
|
|
300
|
-
model,
|
|
301
|
-
prompt: userPrompt,
|
|
302
|
-
max_tokens: maxOutputTokens
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return buildApiProbeUrlCandidates(baseUrl, pathSuffix).map((url) => ({
|
|
307
|
-
url,
|
|
308
|
-
body,
|
|
309
|
-
wireApi
|
|
310
|
-
}));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
274
|
function collectStructuredText(content, pieces) {
|
|
314
275
|
if (typeof content === 'string') {
|
|
315
276
|
const text = content.trim();
|
|
@@ -410,7 +371,6 @@ module.exports = {
|
|
|
410
371
|
buildModelsProbeUrl,
|
|
411
372
|
buildModelProbeSpecs,
|
|
412
373
|
buildModelProbeSpec,
|
|
413
|
-
buildModelConversationSpecs,
|
|
414
374
|
extractModelResponseText,
|
|
415
375
|
hashModelsCacheValue,
|
|
416
376
|
buildModelsCacheKey,
|
package/lib/cli-network-utils.js
CHANGED
|
@@ -73,8 +73,21 @@ async function probeUrl(targetUrl, options = {}) {
|
|
|
73
73
|
'User-Agent': 'codexmate-health-check',
|
|
74
74
|
'Accept': 'application/json'
|
|
75
75
|
};
|
|
76
|
+
if (options.headers && typeof options.headers === 'object') {
|
|
77
|
+
for (const [key, value] of Object.entries(options.headers)) {
|
|
78
|
+
if (value === undefined || value === null) continue;
|
|
79
|
+
headers[key] = String(value);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
76
82
|
if (options.apiKey) {
|
|
77
|
-
|
|
83
|
+
const apiKeyHeader = typeof options.apiKeyHeader === 'string' ? options.apiKeyHeader.trim() : '';
|
|
84
|
+
if (apiKeyHeader) {
|
|
85
|
+
if (headers[apiKeyHeader] === undefined) {
|
|
86
|
+
headers[apiKeyHeader] = String(options.apiKey);
|
|
87
|
+
}
|
|
88
|
+
} else if (headers.Authorization === undefined) {
|
|
89
|
+
headers['Authorization'] = `Bearer ${options.apiKey}`;
|
|
90
|
+
}
|
|
78
91
|
}
|
|
79
92
|
|
|
80
93
|
const timeoutMs = Number.isFinite(options.timeoutMs) ? options.timeoutMs : 0;
|
|
@@ -124,8 +137,21 @@ async function probeJsonPost(targetUrl, body, options = {}) {
|
|
|
124
137
|
'Accept': 'application/json',
|
|
125
138
|
'Content-Type': 'application/json'
|
|
126
139
|
};
|
|
140
|
+
if (options.headers && typeof options.headers === 'object') {
|
|
141
|
+
for (const [key, value] of Object.entries(options.headers)) {
|
|
142
|
+
if (value === undefined || value === null) continue;
|
|
143
|
+
headers[key] = String(value);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
127
146
|
if (options.apiKey) {
|
|
128
|
-
|
|
147
|
+
const apiKeyHeader = typeof options.apiKeyHeader === 'string' ? options.apiKeyHeader.trim() : '';
|
|
148
|
+
if (apiKeyHeader) {
|
|
149
|
+
if (headers[apiKeyHeader] === undefined) {
|
|
150
|
+
headers[apiKeyHeader] = String(options.apiKey);
|
|
151
|
+
}
|
|
152
|
+
} else if (headers.Authorization === undefined) {
|
|
153
|
+
headers['Authorization'] = `Bearer ${options.apiKey}`;
|
|
154
|
+
}
|
|
129
155
|
}
|
|
130
156
|
|
|
131
157
|
const payload = JSON.stringify(body || {});
|
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();
|