fraim-framework 2.0.68 → 2.0.69

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.
@@ -18,13 +18,157 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.FraimLocalMCPServer = void 0;
21
+ exports.FraimLocalMCPServer = exports.FraimTemplateEngine = void 0;
22
22
  const fs_1 = require("fs");
23
23
  const path_1 = require("path");
24
24
  const os_1 = require("os");
25
25
  const child_process_1 = require("child_process");
26
26
  const crypto_1 = require("crypto");
27
27
  const axios_1 = __importDefault(require("axios"));
28
+ const provider_utils_1 = require("../utils/provider-utils");
29
+ const object_utils_1 = require("../utils/object-utils");
30
+ /**
31
+ * Handle template substitution logic separately for better testability
32
+ */
33
+ class FraimTemplateEngine {
34
+ constructor(opts) {
35
+ this.deliveryTemplatesCache = null;
36
+ this.providerTemplatesCache = {};
37
+ this.config = opts.config;
38
+ this.repoInfo = opts.repoInfo;
39
+ this.workingStyle = opts.workingStyle;
40
+ this.projectRoot = opts.projectRoot;
41
+ this.logFn = opts.logFn || (() => { });
42
+ }
43
+ substituteTemplates(content) {
44
+ let result = content;
45
+ // First, substitute config variables with fallback support
46
+ if (this.config) {
47
+ result = result.replace(/\{\{config\.([^}|]+)(?:\s*\|\s*"([^"]+)")?\}\}/g, (match, path, fallback) => {
48
+ try {
49
+ const value = (0, object_utils_1.getNestedValue)(this.config, path.trim());
50
+ if (value !== undefined) {
51
+ return typeof value === 'object'
52
+ ? JSON.stringify(value)
53
+ : String(value);
54
+ }
55
+ if (fallback !== undefined) {
56
+ return fallback;
57
+ }
58
+ return match;
59
+ }
60
+ catch (error) {
61
+ return fallback !== undefined ? fallback : match;
62
+ }
63
+ });
64
+ }
65
+ // Second, substitute {{delivery.*}} templates
66
+ const deliveryValues = this.loadDeliveryTemplates();
67
+ if (deliveryValues) {
68
+ result = result.replace(/\{\{delivery\.([^}]+)\}\}/g, (match, key) => {
69
+ const value = deliveryValues[`delivery.${key.trim()}`];
70
+ return value !== undefined ? value : match;
71
+ });
72
+ }
73
+ // Third, substitute platform-specific action templates
74
+ result = this.substitutePlatformActions(result);
75
+ return result;
76
+ }
77
+ loadDeliveryTemplates() {
78
+ if (this.deliveryTemplatesCache)
79
+ return this.deliveryTemplatesCache;
80
+ const filename = this.workingStyle === 'Conversation' ? 'delivery-conversation.json' : 'delivery-pr.json';
81
+ try {
82
+ let content = null;
83
+ if (this.projectRoot) {
84
+ const deliveryPath = (0, path_1.join)(this.projectRoot, 'registry', 'providers', filename);
85
+ if ((0, fs_1.existsSync)(deliveryPath)) {
86
+ content = (0, fs_1.readFileSync)(deliveryPath, 'utf-8');
87
+ }
88
+ }
89
+ if (!content) {
90
+ const nodeModulesPath = (0, path_1.join)(process.cwd(), 'node_modules', '@fraim', 'framework', 'registry', 'providers', filename);
91
+ if ((0, fs_1.existsSync)(nodeModulesPath)) {
92
+ content = (0, fs_1.readFileSync)(nodeModulesPath, 'utf-8');
93
+ }
94
+ }
95
+ if (content) {
96
+ this.deliveryTemplatesCache = JSON.parse(content);
97
+ return this.deliveryTemplatesCache;
98
+ }
99
+ return null;
100
+ }
101
+ catch (error) {
102
+ this.logFn(`⚠️ Failed to load delivery templates: ${error.message}`);
103
+ return null;
104
+ }
105
+ }
106
+ substitutePlatformActions(content) {
107
+ const provider = (0, provider_utils_1.detectProvider)(this.repoInfo?.url);
108
+ const templates = this.loadProviderTemplates(provider);
109
+ if (!templates)
110
+ return content;
111
+ let result = content;
112
+ for (const [action, template] of Object.entries(templates)) {
113
+ const regex = new RegExp(`\\{\\{${action}\\}\\}`, 'g');
114
+ const renderedTemplate = this.renderActionTemplate(template);
115
+ result = result.replace(regex, renderedTemplate);
116
+ }
117
+ return result;
118
+ }
119
+ loadProviderTemplates(provider) {
120
+ if (this.providerTemplatesCache[provider])
121
+ return this.providerTemplatesCache[provider];
122
+ try {
123
+ let content = null;
124
+ if (this.projectRoot) {
125
+ const providerPath = (0, path_1.join)(this.projectRoot, 'registry', 'providers', `${provider}.json`);
126
+ if ((0, fs_1.existsSync)(providerPath)) {
127
+ content = (0, fs_1.readFileSync)(providerPath, 'utf-8');
128
+ }
129
+ }
130
+ if (!content) {
131
+ const nodeModulesPath = (0, path_1.join)(process.cwd(), 'node_modules', '@fraim', 'framework', 'registry', 'providers', `${provider}.json`);
132
+ if ((0, fs_1.existsSync)(nodeModulesPath)) {
133
+ content = (0, fs_1.readFileSync)(nodeModulesPath, 'utf-8');
134
+ }
135
+ }
136
+ if (content) {
137
+ const templates = JSON.parse(content);
138
+ this.providerTemplatesCache[provider] = templates;
139
+ return templates;
140
+ }
141
+ return null;
142
+ }
143
+ catch (error) {
144
+ this.logFn(`⚠️ Failed to load provider templates: ${error.message}`);
145
+ return null;
146
+ }
147
+ }
148
+ renderActionTemplate(template) {
149
+ if (!this.repoInfo && !this.config?.repository) {
150
+ return template;
151
+ }
152
+ return template.replace(/\{\{([^}]+)\}\}/g, (match, path) => {
153
+ const trimmedPath = path.trim();
154
+ if (trimmedPath.startsWith('repository.')) {
155
+ const repoPath = trimmedPath.substring('repository.'.length);
156
+ if (this.repoInfo) {
157
+ const value = (0, object_utils_1.getNestedValue)(this.repoInfo, repoPath);
158
+ if (value !== undefined)
159
+ return String(value);
160
+ }
161
+ if (this.config?.repository) {
162
+ const value = (0, object_utils_1.getNestedValue)(this.config.repository, repoPath);
163
+ if (value !== undefined)
164
+ return String(value);
165
+ }
166
+ }
167
+ return match;
168
+ });
169
+ }
170
+ }
171
+ exports.FraimTemplateEngine = FraimTemplateEngine;
28
172
  class FraimLocalMCPServer {
29
173
  constructor() {
30
174
  this.config = null;
@@ -33,6 +177,7 @@ class FraimLocalMCPServer {
33
177
  this.pendingRootsRequest = false;
34
178
  this.machineInfo = null;
35
179
  this.repoInfo = null;
180
+ this.engine = null;
36
181
  this.remoteUrl = process.env.FRAIM_REMOTE_URL || 'https://fraim.wellnessatwork.me';
37
182
  this.apiKey = process.env.FRAIM_API_KEY || '';
38
183
  this.localVersion = this.detectLocalVersion();
@@ -40,7 +185,7 @@ class FraimLocalMCPServer {
40
185
  this.logError('❌ FRAIM_API_KEY environment variable is required');
41
186
  process.exit(1);
42
187
  }
43
- this.log('🚀 FRAIM Local MCP Server starting...');
188
+ this.log('🚀 FRAIM Local MCP Server starting... [DEBUG-PROXY-V3]');
44
189
  this.log(`📡 Remote server: ${this.remoteUrl}`);
45
190
  this.log(`🔑 API key: ${this.apiKey.substring(0, 10)}...`);
46
191
  this.log(`Local MCP version: ${this.localVersion}`);
@@ -307,183 +452,17 @@ class FraimLocalMCPServer {
307
452
  }
308
453
  return 'PR';
309
454
  }
310
- /**
311
- * Substitute template variables in content
312
- * Supports:
313
- * 1. {{config.path.to.value}} - Config substitution
314
- * 2. {{config.path.to.value | "fallback instruction"}} - With fallback
315
- * 3. {{delivery.*}} - Working-style-specific delivery templates (from registry/providers/delivery-*.json)
316
- * 4. Platform-specific action templates (GitHub vs ADO, from registry/providers/*.json)
317
- */
318
455
  substituteTemplates(content) {
319
- let result = content;
320
- // First, substitute config variables with fallback support (only if config exists)
321
- if (this.config) {
322
- result = result.replace(/\{\{config\.([^}|]+)(?:\s*\|\s*"([^"]+)")?\}\}/g, (match, path, fallback) => {
323
- try {
324
- const value = this.getNestedValue(this.config, path.trim());
325
- if (value !== undefined) {
326
- // Config value exists - substitute it
327
- return typeof value === 'object'
328
- ? JSON.stringify(value)
329
- : String(value);
330
- }
331
- if (fallback !== undefined) {
332
- // Config value missing - use fallback instruction
333
- return fallback;
334
- }
335
- // No fallback provided - keep placeholder
336
- return match;
337
- }
338
- catch (error) {
339
- // On error, use fallback if provided, otherwise keep placeholder
340
- return fallback !== undefined ? fallback : match;
341
- }
342
- });
343
- }
344
- // Second, substitute {{delivery.*}} templates based on workingStyle
345
- // Loaded from registry/providers/delivery-{mode}.json (same pattern as platform templates)
346
- const deliveryValues = this.loadDeliveryTemplates();
347
- if (deliveryValues) {
348
- result = result.replace(/\{\{delivery\.([^}]+)\}\}/g, (match, key) => {
349
- const value = deliveryValues[`delivery.${key.trim()}`];
350
- return value !== undefined ? value : match;
456
+ if (!this.engine) {
457
+ this.engine = new FraimTemplateEngine({
458
+ config: this.config,
459
+ repoInfo: this.detectRepoInfo(),
460
+ workingStyle: this.getWorkingStyle(),
461
+ projectRoot: this.findProjectRoot(),
462
+ logFn: (msg) => this.log(msg)
351
463
  });
352
464
  }
353
- // Third, substitute platform-specific action templates
354
- // This works independently of config - only needs repo info
355
- result = this.substitutePlatformActions(result);
356
- return result;
357
- }
358
- /**
359
- * Load delivery templates from registry based on workingStyle.
360
- * Follows the same pattern as loadProviderTemplates (registry/providers/*.json).
361
- */
362
- loadDeliveryTemplates() {
363
- const workingStyle = this.getWorkingStyle();
364
- const filename = workingStyle === 'Conversation' ? 'delivery-conversation.json' : 'delivery-pr.json';
365
- try {
366
- const projectRoot = this.findProjectRoot();
367
- if (projectRoot) {
368
- const deliveryPath = (0, path_1.join)(projectRoot, 'registry', 'providers', filename);
369
- if ((0, fs_1.existsSync)(deliveryPath)) {
370
- return JSON.parse((0, fs_1.readFileSync)(deliveryPath, 'utf-8'));
371
- }
372
- }
373
- // Fallback: Try node_modules/@fraim/framework
374
- const nodeModulesPath = (0, path_1.join)(process.cwd(), 'node_modules', '@fraim', 'framework', 'registry', 'providers', filename);
375
- if ((0, fs_1.existsSync)(nodeModulesPath)) {
376
- return JSON.parse((0, fs_1.readFileSync)(nodeModulesPath, 'utf-8'));
377
- }
378
- this.log(`⚠️ Could not find delivery templates: ${filename}`);
379
- return null;
380
- }
381
- catch (error) {
382
- this.log(`⚠️ Failed to load delivery templates: ${error.message}`);
383
- return null;
384
- }
385
- }
386
- /**
387
- * Substitute platform-specific action templates
388
- * Replaces {{action}} with provider-specific MCP tool calls
389
- */
390
- substitutePlatformActions(content) {
391
- // Detect provider from repo info
392
- const provider = this.detectProvider();
393
- // Load provider templates
394
- const templates = this.loadProviderTemplates(provider);
395
- if (!templates) {
396
- return content; // No templates available, return unchanged
397
- }
398
- let result = content;
399
- // Replace {{action}} with provider-specific implementations
400
- for (const [action, template] of Object.entries(templates)) {
401
- const regex = new RegExp(`\\{\\{${action}\\}\\}`, 'g');
402
- // Substitute repository variables in the template
403
- const renderedTemplate = this.renderActionTemplate(template, provider);
404
- result = result.replace(regex, renderedTemplate);
405
- }
406
- return result;
407
- }
408
- /**
409
- * Detect provider from repository info
410
- */
411
- detectProvider() {
412
- if (!this.repoInfo) {
413
- return 'github'; // Default
414
- }
415
- const url = this.repoInfo.url || '';
416
- if (url.includes('dev.azure.com') || url.includes('visualstudio.com')) {
417
- return 'ado';
418
- }
419
- // Check config for explicit provider
420
- if (this.config?.repository?.provider) {
421
- return this.config.repository.provider;
422
- }
423
- return 'github'; // Default
424
- }
425
- /**
426
- * Load provider templates from registry
427
- */
428
- loadProviderTemplates(provider) {
429
- try {
430
- // Try to load from project root first
431
- const projectRoot = this.findProjectRoot();
432
- if (projectRoot) {
433
- const providerPath = (0, path_1.join)(projectRoot, 'registry', 'providers', `${provider}.json`);
434
- if ((0, fs_1.existsSync)(providerPath)) {
435
- return JSON.parse((0, fs_1.readFileSync)(providerPath, 'utf-8'));
436
- }
437
- }
438
- // Fallback: Try to load from node_modules/@fraim/framework
439
- const nodeModulesPath = (0, path_1.join)(process.cwd(), 'node_modules', '@fraim', 'framework', 'registry', 'providers', `${provider}.json`);
440
- if ((0, fs_1.existsSync)(nodeModulesPath)) {
441
- return JSON.parse((0, fs_1.readFileSync)(nodeModulesPath, 'utf-8'));
442
- }
443
- this.log(`⚠️ Could not find provider templates for: ${provider}`);
444
- return null;
445
- }
446
- catch (error) {
447
- this.log(`⚠️ Failed to load provider templates: ${error.message}`);
448
- return null;
449
- }
450
- }
451
- /**
452
- * Render action template with repository variables
453
- */
454
- renderActionTemplate(template, provider) {
455
- if (!this.repoInfo && !this.config?.repository) {
456
- return template; // No repo info available
457
- }
458
- return template.replace(/\{\{([^}]+)\}\}/g, (match, path) => {
459
- const trimmedPath = path.trim();
460
- // Handle repository.* variables
461
- if (trimmedPath.startsWith('repository.')) {
462
- const repoPath = trimmedPath.substring('repository.'.length);
463
- // Try repoInfo first (from git detection)
464
- if (this.repoInfo) {
465
- const value = this.getNestedValue(this.repoInfo, repoPath);
466
- if (value !== undefined)
467
- return String(value);
468
- }
469
- // Fallback to config
470
- if (this.config?.repository) {
471
- const value = this.getNestedValue(this.config.repository, repoPath);
472
- if (value !== undefined)
473
- return String(value);
474
- }
475
- }
476
- // Keep original placeholder if not found
477
- return match;
478
- });
479
- }
480
- /**
481
- * Get nested value from object using dot notation
482
- */
483
- getNestedValue(obj, path) {
484
- return path.split('.').reduce((current, key) => {
485
- return current && current[key] !== undefined ? current[key] : undefined;
486
- }, obj);
465
+ return this.engine.substituteTemplates(content);
487
466
  }
488
467
  /**
489
468
  * Process template substitution in MCP response
@@ -595,14 +574,15 @@ class FraimLocalMCPServer {
595
574
  }
596
575
  return {
597
576
  jsonrpc: '2.0',
598
- id: request.id,
577
+ id: request.id || null,
599
578
  error: {
600
- code: -32603,
601
- message: `Remote server error: ${error.message}`,
579
+ code: status === 401 ? -32001 : -32603,
580
+ message: `Remote server error (${status || 'unknown status'}): ${error.message}`,
602
581
  data: {
603
582
  fraimRequestId: requestId,
604
583
  remoteStatus: status ?? null,
605
- localMcpVersion: this.localVersion
584
+ localMcpVersion: this.localVersion,
585
+ remoteError: remoteData
606
586
  }
607
587
  }
608
588
  };
@@ -741,6 +721,14 @@ class FraimLocalMCPServer {
741
721
  }
742
722
  else {
743
723
  this.logError(`Unknown message type: ${JSON.stringify(message)}`);
724
+ process.stdout.write(JSON.stringify({
725
+ jsonrpc: '2.0',
726
+ error: {
727
+ code: -32600,
728
+ message: 'Invalid Request: Unknown message type'
729
+ },
730
+ id: message.id || null
731
+ }) + '\n');
744
732
  }
745
733
  }
746
734
  catch (error) {
@@ -751,7 +739,8 @@ class FraimLocalMCPServer {
751
739
  error: {
752
740
  code: -32700,
753
741
  message: `Parse error: ${error.message}`
754
- }
742
+ },
743
+ id: null
755
744
  };
756
745
  process.stdout.write(JSON.stringify(errorResponse) + '\n');
757
746
  }
@@ -8,7 +8,7 @@ exports.getDefaultBranch = getDefaultBranch;
8
8
  const child_process_1 = require("child_process");
9
9
  /**
10
10
  * Gets a unique port based on the current git branch name (if it's an issue branch)
11
- * Default to 15300 if not on an issue branch
11
+ * Default to 15302 if not on an issue branch
12
12
  */
13
13
  function getPort() {
14
14
  try {
@@ -24,7 +24,7 @@ function getPort() {
24
24
  catch (e) {
25
25
  // Silently fail and use default
26
26
  }
27
- return Number(process.env.PORT) || Number(process.env.WEBSITES_PORT) || Number(process.env.FRAIM_MCP_PORT) || 15300;
27
+ return Number(process.env.PORT) || Number(process.env.WEBSITES_PORT) || Number(process.env.FRAIM_MCP_PORT) || 15302;
28
28
  }
29
29
  /**
30
30
  * Determines the database name based on the git branch
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNestedValue = getNestedValue;
4
+ /**
5
+ * Safely get a nested value from an object using a dot-path
6
+ */
7
+ function getNestedValue(obj, path) {
8
+ if (!obj)
9
+ return undefined;
10
+ return path.split('.').reduce((current, key) => current && current[key] !== undefined ? current[key] : undefined, obj);
11
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectProvider = detectProvider;
4
+ /**
5
+ * Detect git provider from URL
6
+ */
7
+ function detectProvider(url) {
8
+ if (!url)
9
+ return 'github';
10
+ if (url.includes('dev.azure.com') || url.includes('visualstudio.com')) {
11
+ return 'ado';
12
+ }
13
+ return 'github';
14
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EMAIL_REGEX = void 0;
4
+ exports.validateEmail = validateEmail;
5
+ exports.getRequestMeta = getRequestMeta;
6
+ /**
7
+ * Standard email validation regex
8
+ */
9
+ exports.EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
10
+ /**
11
+ * Validate an email address
12
+ */
13
+ function validateEmail(email) {
14
+ return exports.EMAIL_REGEX.test(email);
15
+ }
16
+ /**
17
+ * Extract IP and UserAgent from an Express Request
18
+ */
19
+ function getRequestMeta(req) {
20
+ const ip = req.headers['x-forwarded-for'] || req.ip || 'unknown';
21
+ const userAgent = req.headers['user-agent'] || 'unknown';
22
+ return { ip, userAgent };
23
+ }
@@ -87,6 +87,13 @@ class WorkflowParser {
87
87
  isSimple: true
88
88
  };
89
89
  }
90
+ /**
91
+ * Get just the overview for an agent starting a workflow
92
+ */
93
+ static getOverview(filePath) {
94
+ const wf = this.parse(filePath);
95
+ return wf ? wf.overview : null;
96
+ }
90
97
  /**
91
98
  * Extract description for listing workflows (intent or first para of overview)
92
99
  */
@@ -102,12 +109,5 @@ class WorkflowParser {
102
109
  const firstPara = wf.overview.split(/\r?\n/).find(l => l.trim() !== '' && !l.startsWith('#'));
103
110
  return firstPara ? firstPara.trim() : '';
104
111
  }
105
- /**
106
- * Get just the overview for an agent starting a workflow
107
- */
108
- static getOverview(filePath) {
109
- const wf = this.parse(filePath);
110
- return wf ? wf.overview : null;
111
- }
112
112
  }
113
113
  exports.WorkflowParser = WorkflowParser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fraim-framework",
3
- "version": "2.0.68",
3
+ "version": "2.0.69",
4
4
  "description": "FRAIM v2: Framework for Rigor-based AI Management - Transform from solo developer to AI manager orchestrating production-ready code with enterprise-grade discipline",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "dev": "tsx --watch src/fraim-mcp-server.ts > server.log 2>&1",
12
12
  "dev:prod": "npm run build && node dist/src/fraim-mcp-server.js > server.log 2>&1",
13
- "build": "tsc && node scripts/copy-ai-manager-rules.js && npm run build:stubs && npm run validate:registry",
13
+ "build": "tsc && npm run build:stubs && node scripts/copy-ai-manager-rules.js && npm run validate:registry",
14
14
  "build:stubs": "tsx scripts/build-stub-registry.ts",
15
15
  "test": "node scripts/test-with-server.js",
16
16
  "start:fraim": "tsx src/fraim-mcp-server.ts",
@@ -20,11 +20,11 @@
20
20
  "manage-keys": "tsx scripts/fraim/manage-keys.ts",
21
21
  "view-signups": "tsx scripts/view-signups.ts",
22
22
  "fraim:init": "npm run build && node index.js init",
23
- "fraim:sync": "node index.js sync",
23
+ "fraim:sync": "node index.js sync --local",
24
24
  "postinstall": "fraim sync --skip-updates || echo 'FRAIM setup skipped.'",
25
25
  "prepublishOnly": "npm run build",
26
26
  "release": "npm version patch && npm publish",
27
- "test-smoke-ci": "tsx --test tests/test-genericization.ts tests/test-cli.ts tests/test-stub-registry.ts tests/test-sync-stubs.ts",
27
+ "test-smoke-ci": "tsx --test tests/test-genericization.ts tests/test-cli.ts tests/test-stub-registry.ts",
28
28
  "test-all-ci": "tsx --test tests/test-*.ts",
29
29
  "validate:registry": "tsx scripts/verify-registry-paths.ts && npm run validate:workflows && npm run validate:platform-agnostic",
30
30
  "validate:workflows": "tsx scripts/validate-workflows.ts",
@@ -67,6 +67,8 @@
67
67
  "@types/node": "^20.0.0",
68
68
  "@types/prompts": "^2.4.9",
69
69
  "fast-glob": "^3.3.3",
70
+ "pptxgenjs": "^4.0.1",
71
+ "qrcode": "^1.5.4",
70
72
  "tsx": "^4.0.0",
71
73
  "typescript": "^5.0.0"
72
74
  },
@@ -93,6 +95,7 @@
93
95
  "cors": "^2.8.5",
94
96
  "dotenv": "^16.4.7",
95
97
  "express": "^5.2.1",
98
+ "html-to-docx": "^1.8.0",
96
99
  "markdown-it": "^14.1.0",
97
100
  "markdown-it-highlightjs": "^4.2.0",
98
101
  "mongodb": "^7.0.0",