@ryanfw/prompt-orchestration-pipeline 0.16.3 → 0.17.0

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.
@@ -11,7 +11,7 @@
11
11
  />
12
12
  <title>Prompt Pipeline Dashboard</title>
13
13
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
14
- <script type="module" crossorigin src="/assets/index-DI_nRqVI.js"></script>
14
+ <script type="module" crossorigin src="/assets/index-xx8otyG0.js"></script>
15
15
  <link rel="stylesheet" crossorigin href="/assets/style-CVd3RRU2.css">
16
16
  </head>
17
17
  <body>
@@ -76,27 +76,62 @@ export async function handleTaskSave(req, res) {
76
76
  const indexPath = taskRegistryPath;
77
77
  let indexContent = await fs.readFile(indexPath, "utf8");
78
78
 
79
- // Check if task name already exists in the index
80
- const taskNamePattern = new RegExp(`^\\s*${taskName}\\s*:`, "m");
79
+ // Check if task name already exists in the index (handles both quoted and unquoted)
80
+ const taskNamePattern = new RegExp(`^\\s*"?${taskName}"?\\s*:`, "m");
81
81
  if (taskNamePattern.test(indexContent)) {
82
82
  return sendJson(res, 400, {
83
83
  error: `Task "${taskName}" already exists in the registry`,
84
84
  });
85
85
  }
86
86
 
87
- // Find the line containing "export default {"
88
- const exportLine = "export default {";
89
- const exportLineIndex = indexContent.indexOf(exportLine);
90
-
91
- if (exportLineIndex === -1) {
87
+ // Detect module format: ESM (export default {) or CommonJS (module.exports = {)
88
+ const esmPattern = /export\s+default\s+\{/;
89
+ const cjsPattern = /module\.exports\s*=\s*\{/;
90
+ const cjsTasksPattern = /module\.exports\s*=\s*\{\s*tasks\s*:\s*\{/;
91
+
92
+ let insertPosition;
93
+ let exportMatch;
94
+ let isNestedCjs = false;
95
+
96
+ if (esmPattern.test(indexContent)) {
97
+ // ESM format: export default { ... }
98
+ exportMatch = indexContent.match(esmPattern);
99
+ insertPosition = indexContent.indexOf("\n", exportMatch.index) + 1;
100
+ } else if (cjsTasksPattern.test(indexContent)) {
101
+ // CommonJS with nested tasks: module.exports = { tasks: { ... } }
102
+ exportMatch = indexContent.match(cjsTasksPattern);
103
+ insertPosition = exportMatch.index + exportMatch[0].length;
104
+ isNestedCjs = true;
105
+ } else if (cjsPattern.test(indexContent)) {
106
+ // CommonJS flat: module.exports = { ... }
107
+ exportMatch = indexContent.match(cjsPattern);
108
+ insertPosition = indexContent.indexOf("\n", exportMatch.index) + 1;
109
+ } else {
92
110
  return sendJson(res, 500, {
93
- error: "Failed to find export default line in index.js",
111
+ error:
112
+ "Failed to find export pattern in index.js (expected 'export default {' or 'module.exports = {')",
94
113
  });
95
114
  }
96
115
 
97
- // Insert new task entry after the export line
98
- const insertPosition = indexContent.indexOf("\n", exportLineIndex) + 1;
99
- const newEntry = ` ${taskName}: "./${filename}",\n`;
116
+ // Insert new task entry after the opening brace line
117
+ // For nested CommonJS, check if we need to add newline to expand single-line format
118
+ let newEntry;
119
+ if (isNestedCjs) {
120
+ // Check if the tasks object already spans multiple lines
121
+ // (i.e., has whitespace and a newline after "tasks: {")
122
+ const remainingContent = indexContent.slice(insertPosition);
123
+ const whitespaceMatch = remainingContent.match(/^\s*\n/);
124
+ if (whitespaceMatch) {
125
+ // Multi-line format: skip whitespace and newline, insert at next position
126
+ insertPosition += whitespaceMatch[0].length;
127
+ newEntry = ` ${taskName}: "./${filename}",\n`;
128
+ } else {
129
+ // Single-line format: add newline to expand it
130
+ newEntry = `\n ${taskName}: "./${filename}",\n`;
131
+ }
132
+ } else {
133
+ newEntry = ` ${taskName}: "./${filename}",\n`;
134
+ }
100
135
 
101
136
  indexContent =
102
137
  indexContent.slice(0, insertPosition) +
@@ -116,4 +151,4 @@ export async function handleTaskSave(req, res) {
116
151
  error: error.message || "Failed to create task",
117
152
  });
118
153
  }
119
- }
154
+ }