MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / parseAutomationAddSpec

Function parseAutomationAddSpec

src/core/bridge_coordinator.ts:15380–15471  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

15378}
15379
15380function parseAutomationAddSpec(text: string) {
15381 const input = String(text ?? '').trim();
15382 const match = input.match(/^\/\S+\s+add\s+(.+)$/iu);
15383 if (!match) {
15384 return null;
15385 }
15386 const rawBody = String(match[1] ?? '').trim();
15387 if (!rawBody) {
15388 return null;
15389 }
15390 const separatorIndex = rawBody.indexOf('|');
15391 if (separatorIndex < 0) {
15392 return null;
15393 }
15394 const left = rawBody.slice(0, separatorIndex).trim();
15395 const prompt = rawBody.slice(separatorIndex + 1).trim();
15396 if (!left || !prompt) {
15397 return null;
15398 }
15399
15400 let mode: 'standalone' | 'thread' = 'standalone';
15401 let scheduleSpec = left;
15402 const modeMatch = left.match(/^(standalone|thread)\b\s*(.*)$/iu);
15403 if (modeMatch) {
15404 mode = modeMatch[1].toLowerCase() === 'thread' ? 'thread' : 'standalone';
15405 scheduleSpec = String(modeMatch[2] ?? '').trim();
15406 }
15407 if (!scheduleSpec) {
15408 return null;
15409 }
15410
15411 const intervalMatch = scheduleSpec.match(/^every\s+(.+)$/iu);
15412 if (intervalMatch) {
15413 const everySeconds = parseAutomationIntervalSeconds(intervalMatch[1]);
15414 if (!everySeconds) {
15415 return null;
15416 }
15417 const label = `every ${formatAutomationIntervalLabel(everySeconds)}`;
15418 return {
15419 mode,
15420 prompt,
15421 title: deriveAutomationTitle(prompt),
15422 schedule: {
15423 kind: 'interval' as const,
15424 everySeconds,
15425 label,
15426 },
15427 };
15428 }
15429
15430 const dailyMatch = scheduleSpec.match(/^daily\s+(\d{1,2}):(\d{2})$/iu);
15431 if (dailyMatch) {
15432 const hour = Number(dailyMatch[1]);
15433 const minute = Number(dailyMatch[2]);
15434 if (!Number.isInteger(hour) || !Number.isInteger(minute) || hour < 0 || hour > 23 || minute < 0 || minute > 59) {
15435 return null;
15436 }
15437 return {

Callers 1

Calls 3

deriveAutomationTitleFunction · 0.85

Tested by

no test coverage detected