Skip to content

Commit ed0defb

Browse files
dickymoorebmadcode
andauthored
fix: normalize workflow manifest schema (#1071)
* fix: normalize workflow manifest schema * fix: escape workflow manifest values safely --------- Co-authored-by: Brian <[email protected]>
1 parent 3bc485d commit ed0defb

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

tools/cli/installers/lib/core/manifest-generator.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ class ManifestGenerator {
581581
*/
582582
async writeWorkflowManifest(cfgDir) {
583583
const csvPath = path.join(cfgDir, 'workflow-manifest.csv');
584+
const escapeCsv = (value) => `"${String(value ?? '').replaceAll('"', '""')}"`;
585+
const parseCsvLine = (line) => {
586+
const columns = line.match(/(".*?"|[^",\s]+)(?=\s*,|\s*$)/g) || [];
587+
return columns.map((c) => c.replaceAll(/^"|"$/g, ''));
588+
};
584589

585590
// Read existing manifest to preserve entries
586591
const existingEntries = new Map();
@@ -592,18 +597,21 @@ class ManifestGenerator {
592597
for (let i = 1; i < lines.length; i++) {
593598
const line = lines[i];
594599
if (line) {
595-
// Parse CSV (simple parsing assuming no commas in quoted fields)
596-
const parts = line.split('","');
600+
const parts = parseCsvLine(line);
597601
if (parts.length >= 4) {
598-
const name = parts[0].replace(/^"/, '');
599-
const module = parts[2];
600-
existingEntries.set(`${module}:${name}`, line);
602+
const [name, description, module, workflowPath] = parts;
603+
existingEntries.set(`${module}:${name}`, {
604+
name,
605+
description,
606+
module,
607+
path: workflowPath,
608+
});
601609
}
602610
}
603611
}
604612
}
605613

606-
// Create CSV header - removed standalone column as ALL workflows now generate commands
614+
// Create CSV header - standalone column removed, everything is canonicalized to 4 columns
607615
let csv = 'name,description,module,path\n';
608616

609617
// Combine existing and new workflows
@@ -617,12 +625,18 @@ class ManifestGenerator {
617625
// Add/update new workflows
618626
for (const workflow of this.workflows) {
619627
const key = `${workflow.module}:${workflow.name}`;
620-
allWorkflows.set(key, `"${workflow.name}","${workflow.description}","${workflow.module}","${workflow.path}"`);
628+
allWorkflows.set(key, {
629+
name: workflow.name,
630+
description: workflow.description,
631+
module: workflow.module,
632+
path: workflow.path,
633+
});
621634
}
622635

623636
// Write all workflows
624637
for (const [, value] of allWorkflows) {
625-
csv += value + '\n';
638+
const row = [escapeCsv(value.name), escapeCsv(value.description), escapeCsv(value.module), escapeCsv(value.path)].join(',');
639+
csv += row + '\n';
626640
}
627641

628642
await fs.writeFile(csvPath, csv);

0 commit comments

Comments
 (0)