@girardmedia/bootspring 2.1.3 → 2.2.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.
Files changed (65) hide show
  1. package/bin/bootspring.js +157 -83
  2. package/claude-commands/agent.md +34 -0
  3. package/claude-commands/bs.md +31 -0
  4. package/claude-commands/build.md +25 -0
  5. package/claude-commands/skill.md +31 -0
  6. package/claude-commands/todo.md +25 -0
  7. package/dist/core/index.d.ts +5814 -0
  8. package/dist/core.js +5779 -0
  9. package/dist/index.js +93883 -0
  10. package/dist/mcp/index.d.ts +1 -0
  11. package/dist/mcp-server.js +2298 -0
  12. package/generators/api-docs.js +3 -3
  13. package/generators/decisions.js +14 -14
  14. package/generators/health.js +6 -6
  15. package/generators/sprint.js +4 -4
  16. package/generators/templates/build-planning.template.js +2 -2
  17. package/generators/visual-doc-generator.js +1 -1
  18. package/package.json +22 -68
  19. package/cli/agent.js +0 -799
  20. package/cli/auth.js +0 -896
  21. package/cli/billing.js +0 -320
  22. package/cli/build.js +0 -1442
  23. package/cli/dashboard.js +0 -123
  24. package/cli/init.js +0 -669
  25. package/cli/mcp.js +0 -240
  26. package/cli/orchestrator.js +0 -240
  27. package/cli/project.js +0 -825
  28. package/cli/quality.js +0 -281
  29. package/cli/skill.js +0 -503
  30. package/cli/switch.js +0 -453
  31. package/cli/todo.js +0 -629
  32. package/cli/update.js +0 -132
  33. package/core/api-client.d.ts +0 -69
  34. package/core/api-client.js +0 -1482
  35. package/core/auth.d.ts +0 -98
  36. package/core/auth.js +0 -737
  37. package/core/build-orchestrator.js +0 -508
  38. package/core/build-state.js +0 -612
  39. package/core/config.d.ts +0 -106
  40. package/core/config.js +0 -1328
  41. package/core/context-loader.js +0 -580
  42. package/core/context.d.ts +0 -61
  43. package/core/context.js +0 -327
  44. package/core/entitlements.d.ts +0 -70
  45. package/core/entitlements.js +0 -322
  46. package/core/index.d.ts +0 -53
  47. package/core/index.js +0 -62
  48. package/core/mcp-config.js +0 -115
  49. package/core/policies.d.ts +0 -43
  50. package/core/policies.js +0 -113
  51. package/core/policy-matrix.js +0 -303
  52. package/core/project-activity.js +0 -175
  53. package/core/redaction.d.ts +0 -5
  54. package/core/redaction.js +0 -63
  55. package/core/self-update.js +0 -259
  56. package/core/session.js +0 -353
  57. package/core/task-extractor.js +0 -1098
  58. package/core/telemetry.d.ts +0 -55
  59. package/core/telemetry.js +0 -617
  60. package/core/tier-enforcement.js +0 -928
  61. package/core/utils.d.ts +0 -90
  62. package/core/utils.js +0 -455
  63. package/core/validation.js +0 -572
  64. package/mcp/server.d.ts +0 -57
  65. package/mcp/server.js +0 -264
@@ -1,928 +0,0 @@
1
- /**
2
- * Bootspring Tier Enforcement
3
- *
4
- * Centralized tier/entitlement enforcement for the CLI.
5
- * Fetches and caches entitlements from the API, enforces limits.
6
- *
7
- * @package bootspring
8
- * @module core/tier-enforcement
9
- */
10
-
11
- const fs = require('fs');
12
- const path = require('path');
13
- const os = require('os');
14
- const auth = require('./auth');
15
-
16
- const BOOTSPRING_DIR = path.join(os.homedir(), '.bootspring');
17
- const ENTITLEMENTS_CACHE_FILE = path.join(BOOTSPRING_DIR, 'entitlements.json');
18
- const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
19
-
20
- // Tier hierarchy for comparison
21
- const TIER_HIERARCHY = {
22
- free: 0,
23
- founder: 1, // Founder = lifetime pro
24
- pro: 1,
25
- team: 2,
26
- enterprise: 3,
27
- custom: 3,
28
- };
29
-
30
- // Default limits per tier (fallback if API unavailable)
31
- const DEFAULT_LIMITS = {
32
- free: {
33
- projects: 1,
34
- apiCallsPerMonth: 500,
35
- devices: 1,
36
- teamSeats: 1,
37
- storage: '100MB',
38
- },
39
- founder: {
40
- projects: 5,
41
- apiCallsPerMonth: 10000,
42
- devices: 3,
43
- teamSeats: 1,
44
- storage: '5GB',
45
- },
46
- pro: {
47
- projects: 5,
48
- apiCallsPerMonth: 10000,
49
- devices: 3,
50
- teamSeats: 1,
51
- storage: '5GB',
52
- },
53
- team: {
54
- projects: 20,
55
- apiCallsPerMonth: 50000,
56
- devices: 10,
57
- teamSeats: 5,
58
- storage: '50GB',
59
- },
60
- enterprise: {
61
- projects: 100,
62
- apiCallsPerMonth: 500000,
63
- devices: 50,
64
- teamSeats: 20,
65
- storage: '500GB',
66
- },
67
- custom: {
68
- projects: 999,
69
- apiCallsPerMonth: 999999,
70
- devices: 999,
71
- teamSeats: 999,
72
- storage: '1TB',
73
- },
74
- };
75
-
76
- // Feature gates by tier
77
- const FEATURE_GATES = {
78
- free: [
79
- 'agents.technical',
80
- 'skills.basic',
81
- 'workflows.basic',
82
- 'telemetry',
83
- // Free preseed: setup, init, generate (local), sync, status, update, export
84
- 'preseed.setup',
85
- 'preseed.init',
86
- 'preseed.generate',
87
- 'preseed.sync',
88
- 'preseed.status',
89
- 'preseed.update',
90
- 'preseed.export',
91
- // Free seed: setup, init, status, export
92
- 'seed.setup',
93
- 'seed.init',
94
- 'seed.status',
95
- 'seed.export',
96
- ],
97
- founder: [
98
- 'agents.technical',
99
- 'agents.business',
100
- 'skills.basic',
101
- 'skills.advanced',
102
- 'workflows.basic',
103
- 'workflows.advanced',
104
- 'telemetry',
105
- 'priority_support',
106
- // Full preseed/seed access
107
- 'preseed.*',
108
- 'seed.*',
109
- ],
110
- pro: [
111
- 'agents.technical',
112
- 'agents.business',
113
- 'skills.basic',
114
- 'skills.advanced',
115
- 'workflows.basic',
116
- 'workflows.advanced',
117
- 'telemetry',
118
- 'priority_support',
119
- // Full preseed/seed access
120
- 'preseed.*',
121
- 'seed.*',
122
- ],
123
- team: [
124
- 'agents.technical',
125
- 'agents.business',
126
- 'agents.enterprise',
127
- 'skills.basic',
128
- 'skills.advanced',
129
- 'skills.enterprise',
130
- 'workflows.basic',
131
- 'workflows.advanced',
132
- 'workflows.enterprise',
133
- 'telemetry',
134
- 'priority_support',
135
- 'team_features',
136
- 'presence',
137
- // Full preseed/seed access
138
- 'preseed.*',
139
- 'seed.*',
140
- ],
141
- enterprise: [
142
- 'agents.*',
143
- 'skills.*',
144
- 'workflows.*',
145
- 'preseed.*',
146
- 'seed.*',
147
- 'telemetry',
148
- 'priority_support',
149
- 'team_features',
150
- 'presence',
151
- 'audit_logs',
152
- 'sso',
153
- 'custom_policies',
154
- ],
155
- custom: [
156
- 'agents.*',
157
- 'skills.*',
158
- 'workflows.*',
159
- 'preseed.*',
160
- 'seed.*',
161
- 'telemetry',
162
- 'priority_support',
163
- 'team_features',
164
- 'presence',
165
- 'audit_logs',
166
- 'sso',
167
- 'custom_policies',
168
- ],
169
- };
170
-
171
- // Preseed commands that require paid tier
172
- const PRESEED_PAID_COMMANDS = [
173
- 'pull', // Cloud sync download
174
- 'push', // Cloud sync upload
175
- 'workflow', // Approval workflows
176
- 'merge', // Document merging
177
- 'start', // Smart entry (includes merge)
178
- ];
179
-
180
- // Seed commands that require paid tier
181
- const SEED_PAID_COMMANDS = [
182
- 'scaffold', // Project generation
183
- 'synthesize', // AI synthesis from preseed
184
- 'generate', // Advanced generation
185
- ];
186
-
187
- // Agent tier requirements
188
- const AGENT_TIERS = {
189
- // Pro tier agents
190
- 'business-strategy-expert': 'pro',
191
- 'competitive-analysis-expert': 'pro',
192
- 'financial-expert': 'pro',
193
- 'growth-expert': 'pro',
194
- 'legal-expert': 'pro',
195
- 'operations-expert': 'pro',
196
- 'sales-expert': 'pro',
197
- // Team tier agents
198
- 'fundraising-expert': 'team',
199
- 'investor-relations-expert': 'team',
200
- 'partnerships-expert': 'team',
201
- 'private-equity-expert': 'team',
202
- };
203
-
204
- // Premium skill patterns (by category or specific pattern)
205
- const PREMIUM_SKILL_CATEGORIES = [
206
- 'ai',
207
- 'payments',
208
- 'security',
209
- 'performance',
210
- 'deployment',
211
- 'email',
212
- 'notifications',
213
- 'realtime',
214
- 'search',
215
- 'seo',
216
- 'files',
217
- 'analytics',
218
- ];
219
-
220
- const PREMIUM_SKILL_PATTERNS = [
221
- 'auth/mfa',
222
- 'auth/rbac',
223
- 'database/multi-tenant',
224
- 'database/full-text-search',
225
- 'testing/e2e',
226
- 'testing/coverage',
227
- 'state/react-query',
228
- 'ui/command-palette',
229
- 'ui/data-tables',
230
- ];
231
-
232
- // Free overrides (free even in premium category)
233
- const FREE_SKILL_OVERRIDES = [
234
- 'security/validation',
235
- 'deployment/docker',
236
- ];
237
-
238
- /**
239
- * Get cached entitlements
240
- * @returns {object|null} Cached entitlements or null
241
- */
242
- function getCachedEntitlements() {
243
- try {
244
- if (fs.existsSync(ENTITLEMENTS_CACHE_FILE)) {
245
- const data = JSON.parse(fs.readFileSync(ENTITLEMENTS_CACHE_FILE, 'utf-8'));
246
-
247
- // Check if cache is still valid
248
- if (data.cachedAt && Date.now() - new Date(data.cachedAt).getTime() < CACHE_TTL_MS) {
249
- return data;
250
- }
251
- }
252
- } catch {
253
- // Ignore cache read errors
254
- }
255
- return null;
256
- }
257
-
258
- /**
259
- * Save entitlements to cache
260
- * @param {object} entitlements - Entitlements data from API
261
- */
262
- function cacheEntitlements(entitlements) {
263
- try {
264
- if (!fs.existsSync(BOOTSPRING_DIR)) {
265
- fs.mkdirSync(BOOTSPRING_DIR, { recursive: true, mode: 0o700 });
266
- }
267
-
268
- const data = {
269
- ...entitlements,
270
- cachedAt: new Date().toISOString(),
271
- };
272
-
273
- fs.writeFileSync(ENTITLEMENTS_CACHE_FILE, JSON.stringify(data, null, 2), { mode: 0o600 });
274
- } catch {
275
- // Ignore cache write errors
276
- }
277
- }
278
-
279
- /**
280
- * Clear entitlements cache
281
- */
282
- function clearCache() {
283
- try {
284
- if (fs.existsSync(ENTITLEMENTS_CACHE_FILE)) {
285
- fs.unlinkSync(ENTITLEMENTS_CACHE_FILE);
286
- }
287
- } catch {
288
- // Ignore
289
- }
290
- }
291
-
292
- /**
293
- * Fetch entitlements from API
294
- * @returns {Promise<object|null>} Entitlements or null if not authenticated
295
- */
296
- async function fetchEntitlements() {
297
- if (!auth.isAuthenticated()) {
298
- return null;
299
- }
300
-
301
- try {
302
- // Lazy require to avoid circular dependency
303
- const api = require('./api-client');
304
- const entitlements = await api.resolveEntitlements();
305
-
306
- // Cache the result
307
- cacheEntitlements(entitlements);
308
-
309
- // Update stored user tier if different
310
- const user = auth.getUser();
311
- if (user && entitlements.tier !== user.tier) {
312
- const creds = auth.getCredentials();
313
- if (creds) {
314
- auth.saveCredentials({
315
- ...creds,
316
- user: { ...creds.user, tier: entitlements.tier }
317
- });
318
- }
319
- }
320
-
321
- return entitlements;
322
- } catch (_error) {
323
- // Return cached data if available, otherwise return default
324
- const cached = getCachedEntitlements();
325
- if (cached) return cached;
326
-
327
- // Return minimal default entitlements
328
- const tier = auth.getTier() || 'free';
329
- return {
330
- tier,
331
- limits: DEFAULT_LIMITS[tier] || DEFAULT_LIMITS.free,
332
- features: FEATURE_GATES[tier] || FEATURE_GATES.free,
333
- agents: { denied: [] },
334
- };
335
- }
336
- }
337
-
338
- /**
339
- * Get current entitlements (cached or fetched)
340
- * @param {object} options - Options
341
- * @param {boolean} options.forceRefresh - Force refresh from API
342
- * @returns {Promise<object>} Entitlements
343
- */
344
- async function getEntitlements(options = {}) {
345
- // Check cache first unless force refresh
346
- if (!options.forceRefresh) {
347
- const cached = getCachedEntitlements();
348
- if (cached) return cached;
349
- }
350
-
351
- // Fetch from API
352
- const fetched = await fetchEntitlements();
353
- if (fetched) return fetched;
354
-
355
- // Fallback to defaults based on stored tier
356
- const tier = auth.getTier() || 'free';
357
- return {
358
- tier,
359
- limits: DEFAULT_LIMITS[tier] || DEFAULT_LIMITS.free,
360
- features: FEATURE_GATES[tier] || FEATURE_GATES.free,
361
- agents: { denied: [] },
362
- };
363
- }
364
-
365
- /**
366
- * Get current tier
367
- * @returns {string} User tier
368
- */
369
- function getTier() {
370
- // Check cache first
371
- const cached = getCachedEntitlements();
372
- if (cached?.tier) return cached.tier;
373
-
374
- // Fall back to stored tier
375
- return auth.getTier() || 'free';
376
- }
377
-
378
- /**
379
- * Get tier level for comparison
380
- * @param {string} tier - Tier name
381
- * @returns {number} Tier level
382
- */
383
- function getTierLevel(tier) {
384
- return TIER_HIERARCHY[tier?.toLowerCase()] ?? 0;
385
- }
386
-
387
- /**
388
- * Check if user tier meets required tier
389
- * @param {string} requiredTier - Required tier
390
- * @param {string} userTier - User's tier (optional, uses current)
391
- * @returns {boolean} Whether user meets tier requirement
392
- */
393
- function meetsTierRequirement(requiredTier, userTier = null) {
394
- const user = userTier || getTier();
395
- return getTierLevel(user) >= getTierLevel(requiredTier);
396
- }
397
-
398
- /**
399
- * Check if user can access an agent
400
- * @param {string} agentId - Agent ID
401
- * @returns {{allowed: boolean, requiredTier?: string, userTier: string}}
402
- */
403
- function checkAgentAccess(agentId) {
404
- const requiredTier = AGENT_TIERS[agentId];
405
- const userTier = getTier();
406
-
407
- if (!requiredTier) {
408
- return { allowed: true, userTier };
409
- }
410
-
411
- return {
412
- allowed: meetsTierRequirement(requiredTier, userTier),
413
- requiredTier,
414
- userTier,
415
- };
416
- }
417
-
418
- /**
419
- * Check if a skill/pattern is premium
420
- * @param {string} skillId - Skill ID (e.g., "auth/oauth" or "external/some-skill")
421
- * @returns {boolean} Whether skill is premium
422
- */
423
- function isSkillPremium(skillId) {
424
- // External skills are always premium
425
- if (skillId.startsWith('external/')) {
426
- return true;
427
- }
428
-
429
- // Check free overrides first
430
- if (FREE_SKILL_OVERRIDES.includes(skillId)) {
431
- return false;
432
- }
433
-
434
- // Check specific premium patterns
435
- if (PREMIUM_SKILL_PATTERNS.includes(skillId)) {
436
- return true;
437
- }
438
-
439
- // Check premium categories
440
- const category = skillId.split('/')[0];
441
- if (PREMIUM_SKILL_CATEGORIES.includes(category)) {
442
- return true;
443
- }
444
-
445
- return false;
446
- }
447
-
448
- /**
449
- * Check if user can access a skill
450
- * @param {string} skillId - Skill ID
451
- * @returns {{allowed: boolean, reason?: string, userTier: string}}
452
- */
453
- function checkSkillAccess(skillId) {
454
- const userTier = getTier();
455
- const isPremium = isSkillPremium(skillId);
456
-
457
- if (!isPremium) {
458
- return { allowed: true, userTier };
459
- }
460
-
461
- // Premium skills require pro or higher
462
- if (meetsTierRequirement('pro', userTier)) {
463
- return { allowed: true, userTier };
464
- }
465
-
466
- return {
467
- allowed: false,
468
- reason: `This skill requires a Pro subscription. Current tier: ${userTier}`,
469
- userTier,
470
- };
471
- }
472
-
473
- /**
474
- * Check if user has a specific feature
475
- * @param {string} feature - Feature name (e.g., "team_features", "sso")
476
- * @returns {boolean} Whether user has feature
477
- */
478
- function hasFeature(feature) {
479
- const tier = getTier();
480
- const features = FEATURE_GATES[tier] || FEATURE_GATES.free;
481
-
482
- // Check for wildcard match
483
- const featureParts = feature.split('.');
484
- for (const f of features) {
485
- if (f === feature) return true;
486
- if (f.endsWith('.*')) {
487
- const prefix = f.slice(0, -2);
488
- if (feature.startsWith(prefix)) return true;
489
- }
490
- }
491
-
492
- return false;
493
- }
494
-
495
- /**
496
- * Get limits for current tier
497
- * @returns {Promise<object>} Limits object
498
- */
499
- async function getLimits() {
500
- const entitlements = await getEntitlements();
501
- return entitlements.limits || DEFAULT_LIMITS[entitlements.tier] || DEFAULT_LIMITS.free;
502
- }
503
-
504
- /**
505
- * Check if user is within a specific limit
506
- * @param {string} limitType - Limit type (projects, apiCallsPerMonth, etc.)
507
- * @param {number} currentUsage - Current usage count
508
- * @returns {Promise<{allowed: boolean, limit: number, usage: number, remaining: number}>}
509
- */
510
- async function checkLimit(limitType, currentUsage) {
511
- const limits = await getLimits();
512
- const limit = limits[limitType] || 0;
513
-
514
- return {
515
- allowed: currentUsage < limit,
516
- limit,
517
- usage: currentUsage,
518
- remaining: Math.max(0, limit - currentUsage),
519
- };
520
- }
521
-
522
- const UPGRADE_URL = 'https://bootspring.com/pricing';
523
- const FEATURE_COPY = {
524
- skill: {
525
- headline: 'Unlock premium skill patterns',
526
- value: 'Get verified advanced patterns and external catalog access for implementation speed.'
527
- },
528
- workflow: {
529
- headline: 'Unlock premium workflow packs',
530
- value: 'Run launch and growth workflows with full checkpoint orchestration.'
531
- },
532
- agent: {
533
- headline: 'Unlock specialist agents',
534
- value: 'Access business and enterprise experts for planning, strategy, and execution.'
535
- },
536
- preseed: {
537
- headline: 'Unlock cloud preseed commands',
538
- value: 'Enable remote sync and workflow-aware document collaboration.'
539
- },
540
- seed: {
541
- headline: 'Unlock advanced seed generation',
542
- value: 'Use scaffold and synthesis flows to generate production-ready project foundations.'
543
- },
544
- general: {
545
- headline: 'Unlock premium capabilities',
546
- value: 'Upgrade to access higher-tier commands, workflows, and limits.'
547
- }
548
- };
549
-
550
- function normalizeToken(value, fallback) {
551
- const normalized = String(value || '')
552
- .trim()
553
- .toLowerCase()
554
- .replace(/[^a-z0-9_-]+/g, '-')
555
- .replace(/^-+|-+$/g, '');
556
- return normalized || fallback;
557
- }
558
-
559
- function normalizePromptPlacement(value) {
560
- const normalized = String(value || '').trim().toLowerCase();
561
- if (normalized === 'banner') return 'banner';
562
- if (normalized === 'footer') return 'footer';
563
- return 'inline';
564
- }
565
-
566
- function parseFeatureContext(feature) {
567
- const rawFeature = String(feature || '').trim() || 'this feature';
568
- const lowerFeature = rawFeature.toLowerCase();
569
-
570
- if (lowerFeature.startsWith('skill:') || lowerFeature.startsWith('skill ')) {
571
- const skillId = rawFeature.replace(/^skill[:\s]*/i, '').trim() || 'premium skill';
572
- return {
573
- feature: rawFeature,
574
- featureType: 'skill',
575
- featureLabel: `Skill ${skillId}`,
576
- capability: 'premium_pattern',
577
- action: 'skill_show'
578
- };
579
- }
580
-
581
- if (lowerFeature.startsWith('workflow:') || lowerFeature.startsWith('workflow ')) {
582
- const workflow = rawFeature.replace(/^workflow[:\s]*/i, '').trim() || 'workflow';
583
- return {
584
- feature: rawFeature,
585
- featureType: 'workflow',
586
- featureLabel: `Workflow ${workflow}`,
587
- capability: 'workflow_pack',
588
- action: 'workflow_open'
589
- };
590
- }
591
-
592
- if (lowerFeature.startsWith('preseed ')) {
593
- const command = rawFeature.replace(/^preseed\s+/i, '').trim() || 'command';
594
- return {
595
- feature: rawFeature,
596
- featureType: 'preseed',
597
- featureLabel: `Preseed ${command}`,
598
- capability: 'preseed_command',
599
- action: command.toLowerCase().replace(/\s+/g, '_')
600
- };
601
- }
602
-
603
- if (lowerFeature.startsWith('seed ')) {
604
- const command = rawFeature.replace(/^seed\s+/i, '').trim() || 'command';
605
- return {
606
- feature: rawFeature,
607
- featureType: 'seed',
608
- featureLabel: `Seed ${command}`,
609
- capability: 'seed_command',
610
- action: command.toLowerCase().replace(/\s+/g, '_')
611
- };
612
- }
613
-
614
- if (lowerFeature.startsWith('agent:') || lowerFeature.includes('expert')) {
615
- const agent = rawFeature.replace(/^agent[:\s]*/i, '').trim() || rawFeature;
616
- return {
617
- feature: rawFeature,
618
- featureType: 'agent',
619
- featureLabel: `Agent ${agent}`,
620
- capability: 'agent_access',
621
- action: 'agent_invoke'
622
- };
623
- }
624
-
625
- return {
626
- feature: rawFeature,
627
- featureType: 'general',
628
- featureLabel: rawFeature,
629
- capability: 'premium_feature',
630
- action: 'feature_access'
631
- };
632
- }
633
-
634
- /**
635
- * Resolve prompt experiment metadata for conversion testing.
636
- * @param {{ placement?: string, variant?: string }} options
637
- * @returns {{ variant: string, placement: 'inline'|'banner'|'footer', source: 'default'|'env'|'override' }}
638
- */
639
- function getUpgradePromptExperiment(options = {}) {
640
- const experiment = String(process.env.BOOTSPRING_UPGRADE_PROMPT_EXPERIMENT || '').trim();
641
- let envVariant = String(process.env.BOOTSPRING_UPGRADE_PROMPT_VARIANT || '').trim();
642
- let envPlacement = String(process.env.BOOTSPRING_UPGRADE_PROMPT_PLACEMENT || '').trim();
643
- if (experiment.includes(':')) {
644
- const [variant, placement] = experiment.split(':', 2);
645
- if (variant) envVariant = variant;
646
- if (placement) envPlacement = placement;
647
- }
648
-
649
- const placement = normalizePromptPlacement(options.placement || envPlacement);
650
- const variant = normalizeToken(options.variant || envVariant || experiment || 'control', 'control');
651
- const source = options.placement || options.variant
652
- ? 'override'
653
- : (experiment || envVariant || envPlacement ? 'env' : 'default');
654
-
655
- return {
656
- variant,
657
- placement,
658
- source
659
- };
660
- }
661
-
662
- /**
663
- * Resolve contextual metadata for blocked upgrade prompts.
664
- * @param {string} feature
665
- * @param {string} requiredTier
666
- * @param {{ capability?: string, action?: string, placement?: string, variant?: string }} options
667
- * @returns {{ feature: string, featureType: string, featureLabel: string, capability: string, action: string, requiredTier: string, userTier: string, placement: 'inline'|'banner'|'footer', variant: string }}
668
- */
669
- function getUpgradePromptContext(feature, requiredTier = 'pro', options = {}) {
670
- const baseContext = parseFeatureContext(feature);
671
- const experiment = getUpgradePromptExperiment(options);
672
- const capability = normalizeToken(options.capability || baseContext.capability, baseContext.capability);
673
- const action = normalizeToken(options.action || baseContext.action, baseContext.action);
674
- const normalizedTier = normalizeToken(requiredTier || 'pro', 'pro');
675
-
676
- return {
677
- ...baseContext,
678
- capability,
679
- action,
680
- requiredTier: normalizedTier,
681
- userTier: getTier(),
682
- placement: experiment.placement,
683
- variant: experiment.variant
684
- };
685
- }
686
-
687
- /**
688
- * Generate upgrade prompt for a blocked feature
689
- * @param {string} feature - Feature or capability that's blocked
690
- * @param {string} requiredTier - Tier required for feature
691
- * @param {{ capability?: string, action?: string, placement?: string, variant?: string }} options
692
- * @returns {string} Formatted upgrade prompt
693
- */
694
- function getUpgradePrompt(feature, requiredTier = 'pro', options = {}) {
695
- const context = getUpgradePromptContext(feature, requiredTier, options);
696
- const featureCopy = FEATURE_COPY[context.featureType] || FEATURE_COPY.general;
697
- const showExperimentTag = context.variant !== 'control' || context.placement !== 'inline';
698
- const requiresLine = `${context.featureLabel} requires ${context.requiredTier} tier or higher.`;
699
- const CYAN = '\x1b[36m';
700
- const YELLOW = '\x1b[33m';
701
- const DIM = '\x1b[2m';
702
- const BOLD = '\x1b[1m';
703
- const RESET = '\x1b[0m';
704
-
705
- const experimentLine = showExperimentTag
706
- ? `${DIM}Experiment: variant=${context.variant}, placement=${context.placement}${RESET}\n`
707
- : '';
708
-
709
- if (context.placement === 'banner') {
710
- return `
711
- ${YELLOW}${BOLD}Upgrade Required${RESET} ${DIM}${requiresLine} Current tier: ${context.userTier}.${RESET}
712
- ${BOLD}${featureCopy.headline}.${RESET} ${DIM}${featureCopy.value}${RESET}
713
- ${CYAN}bootspring billing upgrade${RESET} ${DIM}| ${UPGRADE_URL}${RESET}
714
- ${experimentLine}`;
715
- }
716
-
717
- const placementHint = context.placement === 'footer'
718
- ? `${DIM}Prompt placement: footer${RESET}\n`
719
- : '';
720
-
721
- return `
722
- ${YELLOW}${BOLD}Upgrade Required${RESET}
723
-
724
- ${DIM}${requiresLine}${RESET}
725
- ${DIM}Your current tier: ${context.userTier}${RESET}
726
-
727
- ${BOLD}${featureCopy.headline}${RESET}
728
- ${DIM}${featureCopy.value}${RESET}
729
- ${placementHint}
730
-
731
- ${BOLD}Upgrade options:${RESET}
732
- ${CYAN}bootspring billing upgrade${RESET}
733
-
734
- ${DIM}Or visit: ${UPGRADE_URL}${RESET}
735
- ${experimentLine}
736
- `;
737
- }
738
-
739
- /**
740
- * Format tier badge for display
741
- * @param {string} tier - Tier name
742
- * @returns {string} Formatted badge
743
- */
744
- function formatTierBadge(tier) {
745
- const YELLOW = '\x1b[33m';
746
- const GREEN = '\x1b[32m';
747
- const CYAN = '\x1b[36m';
748
- const RESET = '\x1b[0m';
749
-
750
- switch (tier?.toLowerCase()) {
751
- case 'pro':
752
- case 'founder':
753
- return `${YELLOW}[PRO]${RESET}`;
754
- case 'team':
755
- return `${CYAN}[TEAM]${RESET}`;
756
- case 'enterprise':
757
- case 'custom':
758
- return `${CYAN}[ENT]${RESET}`;
759
- default:
760
- return `${GREEN}[FREE]${RESET}`;
761
- }
762
- }
763
-
764
- /**
765
- * Require a specific tier - throws if not met
766
- * @param {string} requiredTier - Required tier
767
- * @param {string} feature - Feature name for error message
768
- * @throws {Error} If tier requirement not met
769
- */
770
- function requireTier(requiredTier, feature = 'this feature') {
771
- if (!meetsTierRequirement(requiredTier)) {
772
- const error = new Error(`${feature} requires ${requiredTier} tier or higher`);
773
- error.code = 'TIER_REQUIRED';
774
- error.requiredTier = requiredTier;
775
- error.userTier = getTier();
776
- error.upgradePrompt = getUpgradePrompt(feature, requiredTier);
777
- throw error;
778
- }
779
- }
780
-
781
- /**
782
- * Require a specific feature - throws if not available
783
- * @param {string} feature - Feature name
784
- * @throws {Error} If feature not available
785
- */
786
- function requireFeature(feature) {
787
- if (!hasFeature(feature)) {
788
- const error = new Error(`${feature} is not available on your current plan`);
789
- error.code = 'FEATURE_REQUIRED';
790
- error.feature = feature;
791
- error.userTier = getTier();
792
- throw error;
793
- }
794
- }
795
-
796
- /**
797
- * Check if a preseed command requires paid tier
798
- * @param {string} command - Preseed subcommand
799
- * @returns {{allowed: boolean, requiredTier: string, userTier: string, feature: string}}
800
- */
801
- function checkPreseedAccess(command) {
802
- const userTier = getTier();
803
- const isPaidCommand = PRESEED_PAID_COMMANDS.includes(command);
804
-
805
- if (!isPaidCommand) {
806
- return { allowed: true, requiredTier: 'free', userTier, feature: `preseed ${command}` };
807
- }
808
-
809
- // Check if user has preseed.* or specific preseed.command
810
- const hasAccess = hasFeature(`preseed.${command}`) || hasFeature('preseed.*');
811
-
812
- return {
813
- allowed: hasAccess,
814
- requiredTier: 'pro',
815
- userTier,
816
- feature: `preseed ${command}`,
817
- };
818
- }
819
-
820
- /**
821
- * Check if a seed command requires paid tier
822
- * @param {string} command - Seed subcommand
823
- * @returns {{allowed: boolean, requiredTier: string, userTier: string, feature: string}}
824
- */
825
- function checkSeedAccess(command) {
826
- const userTier = getTier();
827
- const isPaidCommand = SEED_PAID_COMMANDS.includes(command);
828
-
829
- if (!isPaidCommand) {
830
- return { allowed: true, requiredTier: 'free', userTier, feature: `seed ${command}` };
831
- }
832
-
833
- // Check if user has seed.* or specific seed.command
834
- const hasAccess = hasFeature(`seed.${command}`) || hasFeature('seed.*');
835
-
836
- return {
837
- allowed: hasAccess,
838
- requiredTier: 'pro',
839
- userTier,
840
- feature: `seed ${command}`,
841
- };
842
- }
843
-
844
- /**
845
- * Require preseed command access - throws if not allowed
846
- * @param {string} command - Preseed subcommand
847
- * @throws {Error} If access not allowed
848
- */
849
- function requirePreseedAccess(command) {
850
- const access = checkPreseedAccess(command);
851
- if (!access.allowed) {
852
- const error = new Error(`preseed ${command} requires ${access.requiredTier} tier or higher`);
853
- error.code = 'TIER_REQUIRED';
854
- error.requiredTier = access.requiredTier;
855
- error.userTier = access.userTier;
856
- error.upgradePrompt = getUpgradePrompt(`preseed ${command}`, access.requiredTier);
857
- throw error;
858
- }
859
- }
860
-
861
- /**
862
- * Require seed command access - throws if not allowed
863
- * @param {string} command - Seed subcommand
864
- * @throws {Error} If access not allowed
865
- */
866
- function requireSeedAccess(command) {
867
- const access = checkSeedAccess(command);
868
- if (!access.allowed) {
869
- const error = new Error(`seed ${command} requires ${access.requiredTier} tier or higher`);
870
- error.code = 'TIER_REQUIRED';
871
- error.requiredTier = access.requiredTier;
872
- error.userTier = access.userTier;
873
- error.upgradePrompt = getUpgradePrompt(`seed ${command}`, access.requiredTier);
874
- throw error;
875
- }
876
- }
877
-
878
- module.exports = {
879
- // Cache management
880
- getCachedEntitlements,
881
- cacheEntitlements,
882
- clearCache,
883
-
884
- // Entitlements
885
- fetchEntitlements,
886
- getEntitlements,
887
-
888
- // Tier checks
889
- getTier,
890
- getTierLevel,
891
- meetsTierRequirement,
892
- requireTier,
893
-
894
- // Agent access
895
- checkAgentAccess,
896
- AGENT_TIERS,
897
-
898
- // Skill access
899
- isSkillPremium,
900
- checkSkillAccess,
901
- PREMIUM_SKILL_CATEGORIES,
902
- PREMIUM_SKILL_PATTERNS,
903
-
904
- // Feature access
905
- hasFeature,
906
- requireFeature,
907
- FEATURE_GATES,
908
-
909
- // Preseed/Seed access
910
- checkPreseedAccess,
911
- checkSeedAccess,
912
- requirePreseedAccess,
913
- requireSeedAccess,
914
- PRESEED_PAID_COMMANDS,
915
- SEED_PAID_COMMANDS,
916
-
917
- // Limits
918
- getLimits,
919
- checkLimit,
920
- DEFAULT_LIMITS,
921
-
922
- // Display helpers
923
- getUpgradePromptExperiment,
924
- getUpgradePromptContext,
925
- getUpgradePrompt,
926
- formatTierBadge,
927
- TIER_HIERARCHY,
928
- };