codexmate 0.1.9 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +0 -4
  2. package/README.vi.md +0 -4
  3. package/README.zh.md +0 -4
  4. package/cli/agents-files.js +27 -3
  5. package/cli/prompt-history.js +171 -0
  6. package/cli/system-prompt-files.js +20 -2
  7. package/cli.js +83 -2694
  8. package/package.json +1 -1
  9. package/web-ui/app.js +39 -56
  10. package/web-ui/index.html +0 -1
  11. package/web-ui/modules/app.computed.dashboard.mjs +0 -3
  12. package/web-ui/modules/app.computed.main-tabs.mjs +0 -474
  13. package/web-ui/modules/app.methods.agents.mjs +90 -0
  14. package/web-ui/modules/app.methods.index.mjs +1 -3
  15. package/web-ui/modules/app.methods.navigation.mjs +8 -3
  16. package/web-ui/modules/app.methods.session-actions.mjs +57 -25
  17. package/web-ui/modules/app.methods.system-prompt.mjs +81 -0
  18. package/web-ui/modules/app.methods.web-ui-preferences.mjs +26 -9
  19. package/web-ui/modules/i18n/locales/en.mjs +10 -265
  20. package/web-ui/modules/i18n/locales/ja.mjs +10 -265
  21. package/web-ui/modules/i18n/locales/vi.mjs +10 -266
  22. package/web-ui/modules/i18n/locales/zh-tw.mjs +10 -265
  23. package/web-ui/modules/i18n/locales/zh.mjs +10 -265
  24. package/web-ui/partials/index/layout-header.html +5 -48
  25. package/web-ui/partials/index/panel-config-claude.html +3 -3
  26. package/web-ui/partials/index/panel-config-codex.html +3 -3
  27. package/web-ui/partials/index/panel-config-kilocode.html +5 -5
  28. package/web-ui/partials/index/panel-config-openclaw.html +3 -3
  29. package/web-ui/partials/index/panel-config-opencode.html +5 -5
  30. package/web-ui/partials/index/panel-dashboard.html +0 -21
  31. package/web-ui/partials/index/panel-prompts.html +52 -0
  32. package/web-ui/partials/index/panel-sessions.html +12 -0
  33. package/web-ui/partials/index/panel-settings.html +35 -0
  34. package/web-ui/res/web-ui-render.precompiled.js +543 -1376
  35. package/web-ui/session-helpers.mjs +0 -16
  36. package/web-ui/styles/modals-core.css +86 -0
  37. package/web-ui/styles/sessions-preview.css +38 -0
  38. package/web-ui/styles/titles-cards.css +2 -2
  39. package/web-ui/styles.css +0 -1
  40. package/lib/automation.js +0 -404
  41. package/lib/task-orchestrator.js +0 -938
  42. package/lib/task-workspace-chat.js +0 -292
  43. package/web-ui/modules/app.methods.task-orchestration.mjs +0 -895
  44. package/web-ui/partials/index/panel-orchestration.html +0 -598
  45. package/web-ui/styles/task-orchestration.css +0 -2979
@@ -85,7 +85,6 @@ export function switchMainTab(tab) {
85
85
  const leavingSessions = previousTab === 'sessions' && nextTab !== 'sessions';
86
86
  const enteringSessionsTab = nextTab === 'sessions';
87
87
  const enteringUsageTab = nextTab === 'usage';
88
- const enteringOrchestrationTab = nextTab === 'orchestration';
89
88
  const enteringPluginsTab = nextTab === 'plugins';
90
89
  emitSessionLoadDebug(this, 'switchMainTab:start', `from=${previousTab}\nto=${nextTab}`);
91
90
  this.mainTab = nextTab;
@@ -141,21 +140,6 @@ export function switchMainTab(tab) {
141
140
  if (enteringUsageTab && !this.sessionsUsageLoadedOnce && typeof this.loadSessionsUsage === 'function') {
142
141
  this.loadSessionsUsage();
143
142
  }
144
- if (enteringOrchestrationTab && typeof this.loadTaskOrchestrationOverview === 'function') {
145
- let orchestrationOverviewLoad = null;
146
- try {
147
- orchestrationOverviewLoad = this.loadTaskOrchestrationOverview({
148
- silent: true,
149
- includeDetail: true
150
- });
151
- } catch (_) {
152
- orchestrationOverviewLoad = null;
153
- }
154
- void Promise.resolve(orchestrationOverviewLoad).catch(() => {});
155
- }
156
- if (nextTab !== 'orchestration' && typeof this.stopTaskOrchestrationPolling === 'function') {
157
- this.stopTaskOrchestrationPolling();
158
- }
159
143
  if (
160
144
  nextTab === 'sessions'
161
145
  && (
@@ -945,3 +945,89 @@
945
945
  .btn-danger-mini {
946
946
  color: var(--color-danger);
947
947
  }
948
+
949
+ .prompt-history-panel {
950
+ margin: 12px 0;
951
+ border: 1px solid var(--color-border-soft);
952
+ border-radius: var(--radius-md);
953
+ background: var(--color-bg-card);
954
+ }
955
+
956
+ .prompt-history-summary {
957
+ display: flex;
958
+ align-items: center;
959
+ justify-content: space-between;
960
+ padding: 10px 12px;
961
+ cursor: default;
962
+ color: var(--color-text-primary);
963
+ font-weight: var(--font-weight-primary);
964
+ }
965
+
966
+ .prompt-history-close {
967
+ margin-left: auto;
968
+ }
969
+
970
+ .prompt-history-body {
971
+ padding: 0 12px 12px;
972
+ display: flex;
973
+ flex-direction: column;
974
+ gap: 10px;
975
+ }
976
+
977
+ .prompt-history-list {
978
+ list-style: none;
979
+ margin: 0;
980
+ padding: 0;
981
+ max-height: 200px;
982
+ overflow-y: auto;
983
+ border: 1px solid var(--color-border-soft);
984
+ border-radius: var(--radius-sm);
985
+ }
986
+
987
+ .prompt-history-item {
988
+ display: flex;
989
+ justify-content: space-between;
990
+ gap: 10px;
991
+ padding: 8px 10px;
992
+ cursor: pointer;
993
+ border-bottom: 1px solid var(--color-border-soft);
994
+ }
995
+
996
+ .prompt-history-item:last-child {
997
+ border-bottom: none;
998
+ }
999
+
1000
+ .prompt-history-item:hover {
1001
+ background: var(--color-bg-hover);
1002
+ }
1003
+
1004
+ .prompt-history-item.active {
1005
+ background: var(--color-bg-active);
1006
+ }
1007
+
1008
+ .prompt-history-time {
1009
+ color: var(--color-text-primary);
1010
+ font-variant-numeric: tabular-nums;
1011
+ }
1012
+
1013
+ .prompt-history-size {
1014
+ color: var(--color-text-secondary);
1015
+ }
1016
+
1017
+ .prompt-history-preview-wrap {
1018
+ display: flex;
1019
+ flex-direction: column;
1020
+ gap: 8px;
1021
+ }
1022
+
1023
+ .prompt-history-preview {
1024
+ margin: 0;
1025
+ padding: 10px;
1026
+ max-height: 240px;
1027
+ overflow: auto;
1028
+ border: 1px solid var(--color-border-soft);
1029
+ border-radius: var(--radius-sm);
1030
+ background: var(--color-bg-inline);
1031
+ white-space: pre-wrap;
1032
+ word-break: break-word;
1033
+ }
@@ -439,6 +439,44 @@
439
439
  color: var(--color-text-tertiary);
440
440
  }
441
441
 
442
+ .session-msg-copy {
443
+ position: absolute;
444
+ right: 12px;
445
+ bottom: 12px;
446
+ border: 1px solid var(--color-border-soft);
447
+ background: var(--color-surface-alt);
448
+ color: var(--color-text-secondary);
449
+ width: 24px;
450
+ height: 24px;
451
+ border-radius: 8px;
452
+ display: inline-flex;
453
+ align-items: center;
454
+ justify-content: center;
455
+ cursor: pointer;
456
+ flex-shrink: 0;
457
+ transition: all var(--transition-fast) var(--ease-spring);
458
+ }
459
+
460
+ .session-msg-copy:hover {
461
+ border-color: var(--color-brand);
462
+ background: var(--color-surface);
463
+ color: var(--color-brand);
464
+ transform: translateY(-1px);
465
+ }
466
+
467
+ .session-msg-copy:active {
468
+ transform: translateY(0);
469
+ }
470
+
471
+ .session-msg-copy svg {
472
+ width: 10px;
473
+ height: 10px;
474
+ }
475
+
476
+ .session-msg.user .session-msg-content {
477
+ padding-right: 36px;
478
+ }
479
+
442
480
  .session-msg-content {
443
481
  font-size: var(--font-size-secondary);
444
482
  line-height: 1.6;
@@ -334,9 +334,9 @@
334
334
  grid-auto-columns: max-content;
335
335
  column-gap: var(--spacing-xs);
336
336
  row-gap: 6px;
337
- align-items: center;
337
+ align-items: start;
338
338
  justify-content: end;
339
- align-self: center;
339
+ align-self: flex-start;
340
340
  }
341
341
 
342
342
  .card-trailing .card-actions {
package/web-ui/styles.css CHANGED
@@ -10,7 +10,6 @@
10
10
  @import url('./styles/sessions-preview.css');
11
11
  @import url('./styles/sessions-usage.css');
12
12
  @import url('./styles/dashboard.css');
13
- @import url('./styles/task-orchestration.css');
14
13
  @import url('./styles/modals-core.css');
15
14
  @import url('./styles/health-check-dialog.css');
16
15
  @import url('./styles/openclaw-structured.css');
package/lib/automation.js DELETED
@@ -1,404 +0,0 @@
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
- };