@codemcp/workflows-core 3.1.20 → 3.1.21-fix-build-after-monorepo.1

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.
@@ -381,14 +381,15 @@ export class ProjectDocsManager {
381
381
  });
382
382
  } catch (error) {
383
383
  // File doesn't exist, which is fine
384
+ const nodeError = error as NodeJS.ErrnoException;
384
385
  if (
385
386
  error instanceof Error &&
386
- 'code' in error &&
387
- error.code !== 'ENOENT'
387
+ 'code' in nodeError &&
388
+ nodeError.code !== 'ENOENT'
388
389
  ) {
389
390
  logger.debug('Failed to remove existing document', {
390
391
  documentPath,
391
- error: error instanceof Error ? error.message : 'Unknown error',
392
+ error: nodeError.message,
392
393
  });
393
394
  }
394
395
  }
@@ -422,7 +423,7 @@ export class ProjectDocsManager {
422
423
  await mkdir(fileDir, { recursive: true });
423
424
 
424
425
  // Write file
425
- await writeFile(filePath, file.content);
426
+ await writeFile(filePath, file.content.toString());
426
427
  }
427
428
  }
428
429
 
@@ -8,6 +8,7 @@ import fs from 'node:fs';
8
8
  import yaml from 'js-yaml';
9
9
  import path from 'node:path';
10
10
  import { fileURLToPath } from 'node:url';
11
+ import { createRequire } from 'node:module';
11
12
  import { createLogger } from './logger.js';
12
13
  import { YamlStateMachine, YamlTransition } from './state-machine-types.js';
13
14
 
@@ -73,27 +74,83 @@ export class StateMachineLoader {
73
74
  }
74
75
 
75
76
  // Fall back to waterfall workflow as default
76
- // Use import.meta.url to get the current file's path in ESM
77
- const currentFileUrl = import.meta.url;
78
- const currentFilePath = fileURLToPath(currentFileUrl);
79
- // Go up from packages/core/dist/ to project root (4 levels up)
80
- const projectRoot = path.dirname(
81
- path.dirname(path.dirname(path.dirname(currentFilePath)))
82
- );
83
- const defaultFilePath = path.join(
84
- projectRoot,
85
- 'resources',
86
- 'workflows',
87
- 'waterfall.yaml'
88
- );
77
+ const defaultFilePath = this.resolveWorkflowPath('waterfall.yaml');
89
78
 
90
79
  logger.info('Loading default state machine file', { defaultFilePath });
91
80
  return this.loadFromFile(defaultFilePath);
92
81
  }
93
82
 
94
83
  /**
95
- * Load state machine from specific file path
84
+ * Resolve workflow path using similar strategy as TemplateManager
96
85
  */
86
+ private resolveWorkflowPath(filename: string): string {
87
+ const strategies: string[] = [];
88
+
89
+ // Strategy 1: Local resources directory (symlinked from root)
90
+ strategies.push(
91
+ path.join(
92
+ path.dirname(fileURLToPath(import.meta.url)),
93
+ '../resources/workflows',
94
+ filename
95
+ )
96
+ );
97
+
98
+ // Strategy 2: From compiled dist directory
99
+ const currentFileUrl = import.meta.url;
100
+ if (currentFileUrl.startsWith('file://')) {
101
+ const currentFilePath = fileURLToPath(currentFileUrl);
102
+ // From dist/state-machine-loader.js -> ../resources/workflows
103
+ strategies.push(
104
+ path.join(
105
+ path.dirname(currentFilePath),
106
+ '../resources/workflows',
107
+ filename
108
+ )
109
+ );
110
+ }
111
+
112
+ // Strategy 3: Current working directory (for development)
113
+ strategies.push(path.join(process.cwd(), 'resources/workflows', filename));
114
+
115
+ // Strategy 4: From node_modules
116
+ strategies.push(
117
+ path.join(
118
+ process.cwd(),
119
+ 'node_modules/@codemcp/workflows-core/resources/workflows',
120
+ filename
121
+ )
122
+ );
123
+
124
+ // Strategy 5: From package directory (for development)
125
+ try {
126
+ const require = createRequire(import.meta.url);
127
+ const packagePath = require.resolve(
128
+ '@codemcp/workflows-core/package.json'
129
+ );
130
+ const packageDir = path.dirname(packagePath);
131
+ strategies.push(path.join(packageDir, 'resources/workflows', filename));
132
+ } catch (_error) {
133
+ // Ignore if package not found
134
+ }
135
+
136
+ // Find the first existing path
137
+ for (const strategy of strategies) {
138
+ try {
139
+ // This will throw if path doesn't exist
140
+ fs.accessSync(strategy);
141
+ logger.debug('Using workflow path', { path: strategy });
142
+ return strategy;
143
+ } catch (_error) {
144
+ // Continue to next strategy
145
+ }
146
+ }
147
+
148
+ // Fallback to first strategy if none found
149
+ const fallback = strategies[0];
150
+ logger.warn('No workflow path found, using fallback', { path: fallback });
151
+ return fallback;
152
+ }
153
+
97
154
  public loadFromFile(filePath: string): YamlStateMachine {
98
155
  try {
99
156
  const yamlContent = fs.readFileSync(path.resolve(filePath), 'utf8');
@@ -45,7 +45,12 @@ export class TemplateManager {
45
45
  private resolveTemplatesPath(): string {
46
46
  const strategies: string[] = [];
47
47
 
48
- // Strategy 1: From compiled dist directory
48
+ // Strategy 1: Local resources directory (symlinked from root)
49
+ strategies.push(
50
+ join(dirname(fileURLToPath(import.meta.url)), '../resources/templates')
51
+ );
52
+
53
+ // Strategy 2: From compiled dist directory
49
54
  const currentFileUrl = import.meta.url;
50
55
  if (currentFileUrl.startsWith('file://')) {
51
56
  const currentFilePath = fileURLToPath(currentFileUrl);
@@ -53,27 +58,29 @@ export class TemplateManager {
53
58
  strategies.push(join(dirname(currentFilePath), '../resources/templates'));
54
59
  }
55
60
 
56
- // Strategy 2: From node_modules
61
+ // Strategy 3: Current working directory (for development)
62
+ strategies.push(join(process.cwd(), 'resources/templates'));
63
+
64
+ // Strategy 4: From node_modules
57
65
  strategies.push(
58
66
  join(
59
67
  process.cwd(),
60
- 'node_modules/responsible-vibe-mcp/resources/templates'
68
+ 'node_modules/@codemcp/workflows-core/resources/templates'
61
69
  )
62
70
  );
63
71
 
64
- // Strategy 3: From package directory (for development)
72
+ // Strategy 5: From package directory (for development)
65
73
  try {
66
74
  const require = createRequire(import.meta.url);
67
- const packagePath = require.resolve('responsible-vibe-mcp/package.json');
75
+ const packagePath = require.resolve(
76
+ '@codemcp/workflows-core/package.json'
77
+ );
68
78
  const packageDir = dirname(packagePath);
69
79
  strategies.push(join(packageDir, 'resources/templates'));
70
80
  } catch (_error) {
71
81
  // Ignore if package not found
72
82
  }
73
83
 
74
- // Strategy 4: Current working directory (for development)
75
- strategies.push(join(process.cwd(), 'resources/templates'));
76
-
77
84
  // Find the first existing path
78
85
  for (const strategy of strategies) {
79
86
  try {
@@ -343,7 +343,12 @@ export class WorkflowManager {
343
343
  const currentFilePath = fileURLToPath(currentFileUrl);
344
344
  const strategies: string[] = [];
345
345
 
346
- // Strategy 1: Relative to current file (development and direct npm scenarios)
346
+ // Strategy 1: Local resources directory (symlinked from root)
347
+ strategies.push(
348
+ path.join(path.dirname(currentFilePath), '../resources/workflows')
349
+ );
350
+
351
+ // Strategy 2: Relative to current file (development and direct npm scenarios)
347
352
  // From packages/core/dist/workflow-manager.js -> ../../../../resources/workflows
348
353
  strategies.push(
349
354
  path.resolve(
@@ -352,7 +357,7 @@ export class WorkflowManager {
352
357
  )
353
358
  );
354
359
 
355
- // Strategy 2: Find package root by looking for package.json with our package name
360
+ // Strategy 3: Find package root by looking for package.json with our package name
356
361
  let currentDir = path.dirname(currentFilePath);
357
362
  for (let i = 0; i < 10; i++) {
358
363
  // Limit search depth
@@ -362,7 +367,7 @@ export class WorkflowManager {
362
367
  const packageJson = JSON.parse(
363
368
  fs.readFileSync(packageJsonPath, 'utf-8')
364
369
  );
365
- if (packageJson.name === 'responsible-vibe-mcp') {
370
+ if (packageJson.name === '@codemcp/workflows-core') {
366
371
  strategies.push(path.join(currentDir, 'resources/workflows'));
367
372
  break;
368
373
  }
@@ -380,7 +385,7 @@ export class WorkflowManager {
380
385
  strategies.push(
381
386
  path.join(
382
387
  process.cwd(),
383
- 'node_modules/responsible-vibe-mcp/resources/workflows'
388
+ 'node_modules/@codemcp/workflows-core/resources/workflows'
384
389
  )
385
390
  );
386
391
 
@@ -389,7 +394,7 @@ export class WorkflowManager {
389
394
  strategies.push(
390
395
  path.join(
391
396
  process.env.NODE_PATH,
392
- 'responsible-vibe-mcp/resources/workflows'
397
+ '@codemcp/workflows-core/resources/workflows'
393
398
  )
394
399
  );
395
400
  }
@@ -418,11 +423,11 @@ export class WorkflowManager {
418
423
  const possiblePaths = [
419
424
  path.join(
420
425
  entryPath,
421
- 'node_modules/responsible-vibe-mcp/resources/workflows'
426
+ 'node_modules/@codemcp/workflows-core/resources/workflows'
422
427
  ),
423
428
  path.join(
424
429
  entryPath,
425
- 'responsible-vibe-mcp/resources/workflows'
430
+ '@codemcp/workflows-core/resources/workflows'
426
431
  ),
427
432
  ];
428
433
  strategies.push(...possiblePaths);