wyrm-mcp 3.2.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.
- package/LICENSE +667 -0
- package/README.md +384 -0
- package/dist/analytics.d.ts +100 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +368 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auto-orchestrator.d.ts +118 -0
- package/dist/auto-orchestrator.d.ts.map +1 -0
- package/dist/auto-orchestrator.js +325 -0
- package/dist/auto-orchestrator.js.map +1 -0
- package/dist/autoconfig.d.ts +89 -0
- package/dist/autoconfig.d.ts.map +1 -0
- package/dist/autoconfig.js +576 -0
- package/dist/autoconfig.js.map +1 -0
- package/dist/cli.d.ts +148 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +281 -0
- package/dist/cli.js.map +1 -0
- package/dist/cloud-backup.d.ts +100 -0
- package/dist/cloud-backup.d.ts.map +1 -0
- package/dist/cloud-backup.js +545 -0
- package/dist/cloud-backup.js.map +1 -0
- package/dist/crypto.d.ts +72 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +164 -0
- package/dist/crypto.js.map +1 -0
- package/dist/database.d.ts +218 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +1058 -0
- package/dist/database.js.map +1 -0
- package/dist/http-auth.d.ts +68 -0
- package/dist/http-auth.d.ts.map +1 -0
- package/dist/http-auth.js +296 -0
- package/dist/http-auth.js.map +1 -0
- package/dist/http-fast.d.ts +13 -0
- package/dist/http-fast.d.ts.map +1 -0
- package/dist/http-fast.js +325 -0
- package/dist/http-fast.js.map +1 -0
- package/dist/http-server.d.ts +12 -0
- package/dist/http-server.d.ts.map +1 -0
- package/dist/http-server.js +383 -0
- package/dist/http-server.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1695 -0
- package/dist/index.js.map +1 -0
- package/dist/license.d.ts +177 -0
- package/dist/license.d.ts.map +1 -0
- package/dist/license.js +405 -0
- package/dist/license.js.map +1 -0
- package/dist/logger.d.ts +76 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +195 -0
- package/dist/logger.js.map +1 -0
- package/dist/performance.d.ts +114 -0
- package/dist/performance.d.ts.map +1 -0
- package/dist/performance.js +228 -0
- package/dist/performance.js.map +1 -0
- package/dist/resilience.d.ts +146 -0
- package/dist/resilience.d.ts.map +1 -0
- package/dist/resilience.js +563 -0
- package/dist/resilience.js.map +1 -0
- package/dist/security.d.ts +68 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +215 -0
- package/dist/security.js.map +1 -0
- package/dist/setup.d.ts +21 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +261 -0
- package/dist/setup.js.map +1 -0
- package/dist/summarizer.d.ts +30 -0
- package/dist/summarizer.d.ts.map +1 -0
- package/dist/summarizer.js +139 -0
- package/dist/summarizer.js.map +1 -0
- package/dist/sync.d.ts +39 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +356 -0
- package/dist/sync.js.map +1 -0
- package/dist/types.d.ts +267 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +30 -0
- package/dist/types.js.map +1 -0
- package/dist/vectors.d.ts +103 -0
- package/dist/vectors.d.ts.map +1 -0
- package/dist/vectors.js +311 -0
- package/dist/vectors.js.map +1 -0
- package/package.json +73 -0
package/dist/license.js
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wyrm License System
|
|
3
|
+
* ED25519 license key generation, signing, and offline verification
|
|
4
|
+
*
|
|
5
|
+
* @copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
|
|
6
|
+
* @license Proprietary - See LICENSE file for details.
|
|
7
|
+
* @module license
|
|
8
|
+
* @version 3.2.0
|
|
9
|
+
*/
|
|
10
|
+
import { createPrivateKey, createPublicKey, sign, verify, generateKeyPairSync, randomBytes, } from 'crypto';
|
|
11
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, chmodSync } from 'fs';
|
|
12
|
+
import { homedir } from 'os';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
// ==================== CONSTANTS ====================
|
|
15
|
+
/** Base32 alphabet without visually-ambiguous characters (no I, L, O, 1) */
|
|
16
|
+
const BASE32_ALPHABET = 'ABCDEFGHJKMNPQRSTUVWXYZ234567890';
|
|
17
|
+
/** License key prefix */
|
|
18
|
+
const KEY_PREFIX = 'WRM';
|
|
19
|
+
/** Bytes of entropy per key segment (4 chars each) */
|
|
20
|
+
const KEY_SEGMENT_COUNT = 4;
|
|
21
|
+
const KEY_SEGMENT_LENGTH = 4;
|
|
22
|
+
/** License file location */
|
|
23
|
+
const WYRM_DIR = join(homedir(), '.wyrm');
|
|
24
|
+
const LICENSE_PATH = join(WYRM_DIR, 'license.json');
|
|
25
|
+
/**
|
|
26
|
+
* Feature gates per tier.
|
|
27
|
+
* Each tier inherits all features from lower tiers plus its own additions.
|
|
28
|
+
*/
|
|
29
|
+
export const TIER_FEATURES = {
|
|
30
|
+
free: ['local_storage', 'all_tools', 'fts_search', 'unlimited_projects'],
|
|
31
|
+
pro: ['cloud_backup', 'encryption', 'analytics', 'priority_support'],
|
|
32
|
+
team: ['shared_memory', 'workspaces', 'admin_dashboard', 'slack_integration'],
|
|
33
|
+
enterprise: ['unlimited_seats', 'sso_saml', 'custom_sla', 'on_premise'],
|
|
34
|
+
};
|
|
35
|
+
/** Ordered tiers for cumulative feature resolution */
|
|
36
|
+
const TIER_ORDER = ['free', 'pro', 'team', 'enterprise'];
|
|
37
|
+
/** Default device limits per tier */
|
|
38
|
+
export const TIER_DEVICE_LIMITS = {
|
|
39
|
+
free: 1,
|
|
40
|
+
pro: 1,
|
|
41
|
+
team: 25,
|
|
42
|
+
enterprise: -1,
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Embedded public key for offline verification.
|
|
46
|
+
* Replace this PEM after running `generateKeyPair()` for the first time.
|
|
47
|
+
*/
|
|
48
|
+
const WYRM_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
49
|
+
MCowBQYDK2VwAyEAVALIDKEYWILLBEPLACEDHEREAFTERGEN00000000000=
|
|
50
|
+
-----END PUBLIC KEY-----`;
|
|
51
|
+
// ==================== SINGLETON STATE ====================
|
|
52
|
+
let currentLicense = null;
|
|
53
|
+
let currentTier = 'free';
|
|
54
|
+
let currentFeatures = new Set(TIER_FEATURES.free);
|
|
55
|
+
// ==================== HELPERS ====================
|
|
56
|
+
/**
|
|
57
|
+
* Resolve the cumulative feature set for a given tier.
|
|
58
|
+
* E.g. `team` gets free + pro + team features.
|
|
59
|
+
*/
|
|
60
|
+
export function resolveFeaturesForTier(tier) {
|
|
61
|
+
const idx = TIER_ORDER.indexOf(tier);
|
|
62
|
+
const features = [];
|
|
63
|
+
for (let i = 0; i <= idx; i++) {
|
|
64
|
+
features.push(...TIER_FEATURES[TIER_ORDER[i]]);
|
|
65
|
+
}
|
|
66
|
+
return [...new Set(features)];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Build the canonical string representation of a license for signing/verification.
|
|
70
|
+
* Field order is fixed so both signer and verifier produce identical payloads.
|
|
71
|
+
*/
|
|
72
|
+
function buildCanonicalPayload(license) {
|
|
73
|
+
return [
|
|
74
|
+
license.key,
|
|
75
|
+
license.product,
|
|
76
|
+
license.tier,
|
|
77
|
+
license.issued_to,
|
|
78
|
+
license.issued_at,
|
|
79
|
+
license.expires_at ?? 'perpetual',
|
|
80
|
+
String(license.max_devices),
|
|
81
|
+
license.features.sort().join(','),
|
|
82
|
+
license.hardware_id ?? '',
|
|
83
|
+
].join('|');
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Encode random bytes into a Base32 string of the given length
|
|
87
|
+
* using our custom visually-unambiguous alphabet.
|
|
88
|
+
*/
|
|
89
|
+
function randomBase32(length) {
|
|
90
|
+
const bytes = randomBytes(length);
|
|
91
|
+
let result = '';
|
|
92
|
+
for (let i = 0; i < length; i++) {
|
|
93
|
+
result += BASE32_ALPHABET[bytes[i] % BASE32_ALPHABET.length];
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
// ==================== KEY GENERATION (SERVER-SIDE) ====================
|
|
98
|
+
/**
|
|
99
|
+
* Generate an Ed25519 key pair for license signing.
|
|
100
|
+
*
|
|
101
|
+
* **Server-side only** — the private key must never be shipped in the client.
|
|
102
|
+
*
|
|
103
|
+
* @returns PEM-encoded public and private keys
|
|
104
|
+
*/
|
|
105
|
+
export function generateKeyPair() {
|
|
106
|
+
const { publicKey, privateKey } = generateKeyPairSync('ed25519', {
|
|
107
|
+
publicKeyEncoding: { type: 'spki', format: 'pem' },
|
|
108
|
+
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
|
|
109
|
+
});
|
|
110
|
+
return { publicKey, privateKey };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Generate a license key in `WRM-XXXX-XXXX-XXXX-XXXX` format.
|
|
114
|
+
*
|
|
115
|
+
* Uses `crypto.randomBytes` mapped onto a Base32 alphabet that excludes
|
|
116
|
+
* visually-ambiguous characters (I, L, O, 1).
|
|
117
|
+
*
|
|
118
|
+
* **Server-side only.**
|
|
119
|
+
*/
|
|
120
|
+
export function generateLicenseKey() {
|
|
121
|
+
const segments = [];
|
|
122
|
+
for (let i = 0; i < KEY_SEGMENT_COUNT; i++) {
|
|
123
|
+
segments.push(randomBase32(KEY_SEGMENT_LENGTH));
|
|
124
|
+
}
|
|
125
|
+
return `${KEY_PREFIX}-${segments.join('-')}`;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Create a new {@link WyrmLicense} with sane defaults for the given tier.
|
|
129
|
+
*
|
|
130
|
+
* **Server-side only.**
|
|
131
|
+
*
|
|
132
|
+
* @param email - Licensee email
|
|
133
|
+
* @param tier - Desired tier
|
|
134
|
+
* @param options - Optional overrides (expiry, hardware binding, extra features)
|
|
135
|
+
*/
|
|
136
|
+
export function createLicense(email, tier, options = {}) {
|
|
137
|
+
const features = resolveFeaturesForTier(tier);
|
|
138
|
+
if (options.extraFeatures) {
|
|
139
|
+
for (const f of options.extraFeatures) {
|
|
140
|
+
if (!features.includes(f))
|
|
141
|
+
features.push(f);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
key: generateLicenseKey(),
|
|
146
|
+
product: 'wyrm',
|
|
147
|
+
tier,
|
|
148
|
+
issued_to: email,
|
|
149
|
+
issued_at: new Date().toISOString(),
|
|
150
|
+
expires_at: options.expiresAt ?? null,
|
|
151
|
+
max_devices: options.maxDevices ?? TIER_DEVICE_LIMITS[tier],
|
|
152
|
+
features,
|
|
153
|
+
hardware_id: options.hardwareId,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Sign a {@link WyrmLicense} with an Ed25519 private key.
|
|
158
|
+
*
|
|
159
|
+
* **Server-side only.**
|
|
160
|
+
*
|
|
161
|
+
* @param license - The license data to sign
|
|
162
|
+
* @param privateKeyPem - PEM-encoded Ed25519 private key
|
|
163
|
+
* @returns The license bundled with its base64 signature
|
|
164
|
+
*/
|
|
165
|
+
export function signLicense(license, privateKeyPem) {
|
|
166
|
+
const payload = buildCanonicalPayload(license);
|
|
167
|
+
const key = createPrivateKey(privateKeyPem);
|
|
168
|
+
const sig = sign(null, Buffer.from(payload, 'utf-8'), key);
|
|
169
|
+
return {
|
|
170
|
+
license,
|
|
171
|
+
signature: sig.toString('base64'),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// ==================== VERIFICATION (CLIENT-SIDE / OFFLINE) ====================
|
|
175
|
+
/**
|
|
176
|
+
* Verify a {@link SignedLicense} against an Ed25519 public key.
|
|
177
|
+
*
|
|
178
|
+
* Performs three checks:
|
|
179
|
+
* 1. Signature validity (Ed25519)
|
|
180
|
+
* 2. Product field matches "wyrm"
|
|
181
|
+
* 3. Expiry date (if present)
|
|
182
|
+
*
|
|
183
|
+
* Works fully offline with zero external dependencies.
|
|
184
|
+
*
|
|
185
|
+
* @param signed - The signed license bundle
|
|
186
|
+
* @param publicKeyPem - Optional PEM override; defaults to the embedded key
|
|
187
|
+
*/
|
|
188
|
+
export function verifyLicense(signed, publicKeyPem) {
|
|
189
|
+
const freeFallback = {
|
|
190
|
+
valid: false,
|
|
191
|
+
tier: 'free',
|
|
192
|
+
features: [...TIER_FEATURES.free],
|
|
193
|
+
expiresAt: null,
|
|
194
|
+
};
|
|
195
|
+
try {
|
|
196
|
+
const { license, signature } = signed;
|
|
197
|
+
// Product check
|
|
198
|
+
if (license.product !== 'wyrm') {
|
|
199
|
+
return { ...freeFallback, error: 'Invalid product identifier' };
|
|
200
|
+
}
|
|
201
|
+
// Tier validity
|
|
202
|
+
if (!TIER_ORDER.includes(license.tier)) {
|
|
203
|
+
return { ...freeFallback, error: `Unknown tier: ${license.tier}` };
|
|
204
|
+
}
|
|
205
|
+
// Signature verification
|
|
206
|
+
const payload = buildCanonicalPayload(license);
|
|
207
|
+
const pem = publicKeyPem ?? WYRM_PUBLIC_KEY;
|
|
208
|
+
let key;
|
|
209
|
+
try {
|
|
210
|
+
key = createPublicKey(pem);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return { ...freeFallback, error: 'Invalid public key' };
|
|
214
|
+
}
|
|
215
|
+
const isValid = verify(null, Buffer.from(payload, 'utf-8'), key, Buffer.from(signature, 'base64'));
|
|
216
|
+
if (!isValid) {
|
|
217
|
+
return { ...freeFallback, error: 'Invalid signature — license may be tampered' };
|
|
218
|
+
}
|
|
219
|
+
// Expiry check
|
|
220
|
+
if (license.expires_at !== null) {
|
|
221
|
+
const expiry = new Date(license.expires_at);
|
|
222
|
+
if (isNaN(expiry.getTime())) {
|
|
223
|
+
return { ...freeFallback, error: 'Malformed expiry date' };
|
|
224
|
+
}
|
|
225
|
+
if (expiry.getTime() < Date.now()) {
|
|
226
|
+
return {
|
|
227
|
+
valid: false,
|
|
228
|
+
tier: license.tier,
|
|
229
|
+
features: [...TIER_FEATURES.free],
|
|
230
|
+
expiresAt: license.expires_at,
|
|
231
|
+
error: `License expired on ${license.expires_at}`,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
valid: true,
|
|
237
|
+
tier: license.tier,
|
|
238
|
+
features: [...license.features],
|
|
239
|
+
expiresAt: license.expires_at,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
244
|
+
return { ...freeFallback, error: `Verification failed: ${message}` };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// ==================== FEATURE GATES ====================
|
|
248
|
+
/**
|
|
249
|
+
* Check whether a specific feature is available in the current license.
|
|
250
|
+
*
|
|
251
|
+
* @param feature - Feature flag name (e.g. `"encryption"`, `"sso_saml"`)
|
|
252
|
+
*/
|
|
253
|
+
export function hasFeature(feature) {
|
|
254
|
+
return currentFeatures.has(feature);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get the current active license tier.
|
|
258
|
+
* Defaults to `"free"` when no valid license is loaded.
|
|
259
|
+
*/
|
|
260
|
+
export function getTier() {
|
|
261
|
+
return currentTier;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Return a summary of the currently-loaded license state.
|
|
265
|
+
*/
|
|
266
|
+
export function getLicenseInfo() {
|
|
267
|
+
if (!currentLicense) {
|
|
268
|
+
return {
|
|
269
|
+
tier: 'free',
|
|
270
|
+
features: [...TIER_FEATURES.free],
|
|
271
|
+
expiresAt: null,
|
|
272
|
+
valid: false,
|
|
273
|
+
issuedTo: null,
|
|
274
|
+
key: null,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const validation = verifyLicense(currentLicense);
|
|
278
|
+
return {
|
|
279
|
+
tier: validation.tier,
|
|
280
|
+
features: validation.features,
|
|
281
|
+
expiresAt: validation.expiresAt,
|
|
282
|
+
valid: validation.valid,
|
|
283
|
+
issuedTo: currentLicense.license.issued_to,
|
|
284
|
+
key: currentLicense.license.key,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
// ==================== PERSISTENCE ====================
|
|
288
|
+
/**
|
|
289
|
+
* Load a signed license from `~/.wyrm/license.json`.
|
|
290
|
+
*
|
|
291
|
+
* @returns The parsed {@link SignedLicense} or `null` if not found / unparseable
|
|
292
|
+
*/
|
|
293
|
+
export function loadLicense() {
|
|
294
|
+
try {
|
|
295
|
+
if (!existsSync(LICENSE_PATH))
|
|
296
|
+
return null;
|
|
297
|
+
const raw = readFileSync(LICENSE_PATH, 'utf-8');
|
|
298
|
+
const parsed = JSON.parse(raw);
|
|
299
|
+
// Basic shape check
|
|
300
|
+
if (!parsed.license || !parsed.signature)
|
|
301
|
+
return null;
|
|
302
|
+
if (!parsed.license.key || !parsed.license.tier)
|
|
303
|
+
return null;
|
|
304
|
+
return parsed;
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Persist a signed license to `~/.wyrm/license.json`.
|
|
312
|
+
* File permissions are set to `0o600` (owner read/write only).
|
|
313
|
+
*
|
|
314
|
+
* @param signed - The signed license to save
|
|
315
|
+
*/
|
|
316
|
+
export function saveLicense(signed) {
|
|
317
|
+
if (!existsSync(WYRM_DIR)) {
|
|
318
|
+
mkdirSync(WYRM_DIR, { recursive: true });
|
|
319
|
+
}
|
|
320
|
+
const json = JSON.stringify(signed, null, 2);
|
|
321
|
+
writeFileSync(LICENSE_PATH, json, { encoding: 'utf-8', mode: 0o600 });
|
|
322
|
+
// Ensure permissions even if file existed previously
|
|
323
|
+
chmodSync(LICENSE_PATH, 0o600);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Activate a license from a JSON string (e.g. pasted by the user).
|
|
327
|
+
*
|
|
328
|
+
* Parses, verifies, and — if valid — persists the license and updates
|
|
329
|
+
* the in-memory singleton state.
|
|
330
|
+
*
|
|
331
|
+
* @param licenseString - JSON-encoded {@link SignedLicense}
|
|
332
|
+
* @returns Validation result
|
|
333
|
+
*/
|
|
334
|
+
export function activateLicense(licenseString) {
|
|
335
|
+
let signed;
|
|
336
|
+
try {
|
|
337
|
+
signed = JSON.parse(licenseString);
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
return {
|
|
341
|
+
valid: false,
|
|
342
|
+
tier: 'free',
|
|
343
|
+
features: [...TIER_FEATURES.free],
|
|
344
|
+
expiresAt: null,
|
|
345
|
+
error: 'Invalid license format — expected JSON',
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
if (!signed.license || !signed.signature) {
|
|
349
|
+
return {
|
|
350
|
+
valid: false,
|
|
351
|
+
tier: 'free',
|
|
352
|
+
features: [...TIER_FEATURES.free],
|
|
353
|
+
expiresAt: null,
|
|
354
|
+
error: 'Malformed license — missing license data or signature',
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
const validation = verifyLicense(signed);
|
|
358
|
+
if (validation.valid) {
|
|
359
|
+
saveLicense(signed);
|
|
360
|
+
currentLicense = signed;
|
|
361
|
+
currentTier = validation.tier;
|
|
362
|
+
currentFeatures = new Set(validation.features);
|
|
363
|
+
}
|
|
364
|
+
return validation;
|
|
365
|
+
}
|
|
366
|
+
// ==================== INITIALIZATION ====================
|
|
367
|
+
/**
|
|
368
|
+
* Initialize the license subsystem on startup.
|
|
369
|
+
*
|
|
370
|
+
* Attempts to load and verify `~/.wyrm/license.json`.
|
|
371
|
+
* Falls back to the free tier on any failure.
|
|
372
|
+
*
|
|
373
|
+
* Call this once during MCP server boot.
|
|
374
|
+
*/
|
|
375
|
+
export function initializeLicense() {
|
|
376
|
+
const signed = loadLicense();
|
|
377
|
+
if (!signed) {
|
|
378
|
+
currentLicense = null;
|
|
379
|
+
currentTier = 'free';
|
|
380
|
+
currentFeatures = new Set(TIER_FEATURES.free);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const validation = verifyLicense(signed);
|
|
384
|
+
if (validation.valid) {
|
|
385
|
+
currentLicense = signed;
|
|
386
|
+
currentTier = validation.tier;
|
|
387
|
+
currentFeatures = new Set(validation.features);
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
// Invalid / expired — degrade gracefully
|
|
391
|
+
currentLicense = null;
|
|
392
|
+
currentTier = 'free';
|
|
393
|
+
currentFeatures = new Set(TIER_FEATURES.free);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Reset the singleton state to free tier.
|
|
398
|
+
* Useful for testing or license deactivation.
|
|
399
|
+
*/
|
|
400
|
+
export function resetLicense() {
|
|
401
|
+
currentLicense = null;
|
|
402
|
+
currentTier = 'free';
|
|
403
|
+
currentFeatures = new Set(TIER_FEATURES.free);
|
|
404
|
+
}
|
|
405
|
+
//# sourceMappingURL=license.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"license.js","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,IAAI,EACJ,MAAM,EACN,mBAAmB,EACnB,WAAW,GAEZ,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA6C5B,sDAAsD;AAEtD,4EAA4E;AAC5E,MAAM,eAAe,GAAG,kCAAkC,CAAC;AAE3D,yBAAyB;AACzB,MAAM,UAAU,GAAG,KAAK,CAAC;AAEzB,sDAAsD;AACtD,MAAM,iBAAiB,GAAG,CAAC,CAAC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C;SAAM,CAAC;QACN,yCAAyC;QACzC,cAAc,GAAG,IAAI,CAAC;QACtB,WAAW,GAAG,MAAM,CAAC;QACrB,eAAe,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,cAAc,GAAG,IAAI,CAAC;IACtB,WAAW,GAAG,MAAM,CAAC;IACrB,eAAe,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wyrm Logger - Structured logging with log levels
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
|
|
5
|
+
* @license Proprietary - See LICENSE file for details.
|
|
6
|
+
* @module logger
|
|
7
|
+
* @version 3.0.0
|
|
8
|
+
*/
|
|
9
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
10
|
+
export interface LogEntry {
|
|
11
|
+
timestamp: string;
|
|
12
|
+
level: LogLevel;
|
|
13
|
+
message: string;
|
|
14
|
+
context?: Record<string, unknown>;
|
|
15
|
+
correlationId?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface LoggerConfig {
|
|
18
|
+
level: LogLevel;
|
|
19
|
+
file?: string;
|
|
20
|
+
console?: boolean;
|
|
21
|
+
json?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Wyrm Logger - Structured logging for the memory system
|
|
25
|
+
*/
|
|
26
|
+
export declare class WyrmLogger {
|
|
27
|
+
private config;
|
|
28
|
+
private correlationId?;
|
|
29
|
+
private logDir;
|
|
30
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
31
|
+
/**
|
|
32
|
+
* Set correlation ID for request tracing
|
|
33
|
+
*/
|
|
34
|
+
setCorrelationId(id: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Generate a new correlation ID
|
|
37
|
+
*/
|
|
38
|
+
generateCorrelationId(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Check if a log level should be logged
|
|
41
|
+
*/
|
|
42
|
+
private shouldLog;
|
|
43
|
+
/**
|
|
44
|
+
* Format log entry
|
|
45
|
+
*/
|
|
46
|
+
private format;
|
|
47
|
+
/**
|
|
48
|
+
* Write log entry
|
|
49
|
+
*/
|
|
50
|
+
private log;
|
|
51
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
52
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
53
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
54
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
55
|
+
/**
|
|
56
|
+
* Log with timing measurement
|
|
57
|
+
*/
|
|
58
|
+
time<T>(label: string, fn: () => T): T;
|
|
59
|
+
/**
|
|
60
|
+
* Async timing
|
|
61
|
+
*/
|
|
62
|
+
timeAsync<T>(label: string, fn: () => Promise<T>): Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Create a child logger with additional context
|
|
65
|
+
*/
|
|
66
|
+
child(context: Record<string, unknown>): WyrmLogger;
|
|
67
|
+
}
|
|
68
|
+
export declare function getLogger(): WyrmLogger;
|
|
69
|
+
export declare function createLogger(config: Partial<LoggerConfig>): WyrmLogger;
|
|
70
|
+
export declare const logger: {
|
|
71
|
+
debug: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
72
|
+
info: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
73
|
+
warn: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
74
|
+
error: (msg: string, ctx?: Record<string, unknown>) => void;
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM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AAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI/D;;OAEG;IACH,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IActC;;OAEG;IACG,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAcnE;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU;CASpD;AAKD,wBAAgB,SAAS,IAAI,UAAU,CAUtC;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,UAAU,CAEtE;AAGD,eAAO,MAAM,MAAM;iBACJ,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBACtC,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBACrC,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;iBACpC,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CACnD,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wyrm Logger - Structured logging with log levels
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
|
|
5
|
+
* @license Proprietary - See LICENSE file for details.
|
|
6
|
+
* @module logger
|
|
7
|
+
* @version 3.0.0
|
|
8
|
+
*/
|
|
9
|
+
import { appendFileSync, existsSync, mkdirSync } from 'fs';
|
|
10
|
+
import { homedir } from 'os';
|
|
11
|
+
import { join } from 'path';
|
|
12
|
+
const LOG_LEVELS = {
|
|
13
|
+
debug: 0,
|
|
14
|
+
info: 1,
|
|
15
|
+
warn: 2,
|
|
16
|
+
error: 3,
|
|
17
|
+
};
|
|
18
|
+
const LOG_COLORS = {
|
|
19
|
+
debug: '\x1b[36m', // Cyan
|
|
20
|
+
info: '\x1b[32m', // Green
|
|
21
|
+
warn: '\x1b[33m', // Yellow
|
|
22
|
+
error: '\x1b[31m', // Red
|
|
23
|
+
};
|
|
24
|
+
const RESET = '\x1b[0m';
|
|
25
|
+
const BOLD = '\x1b[1m';
|
|
26
|
+
const DIM = '\x1b[2m';
|
|
27
|
+
/**
|
|
28
|
+
* Wyrm Logger - Structured logging for the memory system
|
|
29
|
+
*/
|
|
30
|
+
export class WyrmLogger {
|
|
31
|
+
config;
|
|
32
|
+
correlationId;
|
|
33
|
+
logDir;
|
|
34
|
+
constructor(config) {
|
|
35
|
+
this.config = {
|
|
36
|
+
level: config?.level ?? 'info',
|
|
37
|
+
console: config?.console ?? true,
|
|
38
|
+
json: config?.json ?? false,
|
|
39
|
+
file: config?.file,
|
|
40
|
+
};
|
|
41
|
+
this.logDir = join(homedir(), '.wyrm', 'logs');
|
|
42
|
+
if (!existsSync(this.logDir)) {
|
|
43
|
+
mkdirSync(this.logDir, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Set correlation ID for request tracing
|
|
48
|
+
*/
|
|
49
|
+
setCorrelationId(id) {
|
|
50
|
+
this.correlationId = id;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generate a new correlation ID
|
|
54
|
+
*/
|
|
55
|
+
generateCorrelationId() {
|
|
56
|
+
this.correlationId = `wyrm-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
57
|
+
return this.correlationId;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if a log level should be logged
|
|
61
|
+
*/
|
|
62
|
+
shouldLog(level) {
|
|
63
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.config.level];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Format log entry
|
|
67
|
+
*/
|
|
68
|
+
format(entry) {
|
|
69
|
+
if (this.config.json) {
|
|
70
|
+
return JSON.stringify(entry);
|
|
71
|
+
}
|
|
72
|
+
const color = LOG_COLORS[entry.level];
|
|
73
|
+
const levelStr = entry.level.toUpperCase().padEnd(5);
|
|
74
|
+
const time = entry.timestamp.split('T')[1]?.split('.')[0] || entry.timestamp;
|
|
75
|
+
let msg = `${DIM}${time}${RESET} ${color}${BOLD}${levelStr}${RESET} ${entry.message}`;
|
|
76
|
+
if (entry.context && Object.keys(entry.context).length > 0) {
|
|
77
|
+
msg += ` ${DIM}${JSON.stringify(entry.context)}${RESET}`;
|
|
78
|
+
}
|
|
79
|
+
if (entry.correlationId) {
|
|
80
|
+
msg += ` ${DIM}[${entry.correlationId}]${RESET}`;
|
|
81
|
+
}
|
|
82
|
+
return msg;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Write log entry
|
|
86
|
+
*/
|
|
87
|
+
log(level, message, context) {
|
|
88
|
+
if (!this.shouldLog(level))
|
|
89
|
+
return;
|
|
90
|
+
const entry = {
|
|
91
|
+
timestamp: new Date().toISOString(),
|
|
92
|
+
level,
|
|
93
|
+
message,
|
|
94
|
+
context,
|
|
95
|
+
correlationId: this.correlationId,
|
|
96
|
+
};
|
|
97
|
+
const formatted = this.format(entry);
|
|
98
|
+
if (this.config.console) {
|
|
99
|
+
const stream = level === 'error' ? console.error : console.log;
|
|
100
|
+
stream(formatted);
|
|
101
|
+
}
|
|
102
|
+
if (this.config.file) {
|
|
103
|
+
try {
|
|
104
|
+
const logPath = join(this.logDir, this.config.file);
|
|
105
|
+
appendFileSync(logPath, (this.config.json ? formatted : JSON.stringify(entry)) + '\n');
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// Silent fail for file writes
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Log level methods
|
|
113
|
+
debug(message, context) {
|
|
114
|
+
this.log('debug', message, context);
|
|
115
|
+
}
|
|
116
|
+
info(message, context) {
|
|
117
|
+
this.log('info', message, context);
|
|
118
|
+
}
|
|
119
|
+
warn(message, context) {
|
|
120
|
+
this.log('warn', message, context);
|
|
121
|
+
}
|
|
122
|
+
error(message, context) {
|
|
123
|
+
this.log('error', message, context);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Log with timing measurement
|
|
127
|
+
*/
|
|
128
|
+
time(label, fn) {
|
|
129
|
+
const start = performance.now();
|
|
130
|
+
try {
|
|
131
|
+
const result = fn();
|
|
132
|
+
const duration = performance.now() - start;
|
|
133
|
+
this.debug(`${label} completed`, { duration: `${duration.toFixed(2)}ms` });
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
const duration = performance.now() - start;
|
|
138
|
+
this.error(`${label} failed`, { duration: `${duration.toFixed(2)}ms`, error: String(error) });
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Async timing
|
|
144
|
+
*/
|
|
145
|
+
async timeAsync(label, fn) {
|
|
146
|
+
const start = performance.now();
|
|
147
|
+
try {
|
|
148
|
+
const result = await fn();
|
|
149
|
+
const duration = performance.now() - start;
|
|
150
|
+
this.debug(`${label} completed`, { duration: `${duration.toFixed(2)}ms` });
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
const duration = performance.now() - start;
|
|
155
|
+
this.error(`${label} failed`, { duration: `${duration.toFixed(2)}ms`, error: String(error) });
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a child logger with additional context
|
|
161
|
+
*/
|
|
162
|
+
child(context) {
|
|
163
|
+
const child = new WyrmLogger(this.config);
|
|
164
|
+
child.correlationId = this.correlationId;
|
|
165
|
+
const originalLog = child.log.bind(child);
|
|
166
|
+
child.log = (level, message, ctx) => {
|
|
167
|
+
originalLog(level, message, { ...context, ...ctx });
|
|
168
|
+
};
|
|
169
|
+
return child;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Default logger instance
|
|
173
|
+
let defaultLogger = null;
|
|
174
|
+
export function getLogger() {
|
|
175
|
+
if (!defaultLogger) {
|
|
176
|
+
defaultLogger = new WyrmLogger({
|
|
177
|
+
level: process.env.WYRM_LOG_LEVEL || 'info',
|
|
178
|
+
console: process.env.WYRM_LOG_CONSOLE !== 'false',
|
|
179
|
+
json: process.env.WYRM_LOG_JSON === 'true',
|
|
180
|
+
file: 'wyrm.log',
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return defaultLogger;
|
|
184
|
+
}
|
|
185
|
+
export function createLogger(config) {
|
|
186
|
+
return new WyrmLogger(config);
|
|
187
|
+
}
|
|
188
|
+
// Convenience exports
|
|
189
|
+
export const logger = {
|
|
190
|
+
debug: (msg, ctx) => getLogger().debug(msg, ctx),
|
|
191
|
+
info: (msg, ctx) => getLogger().info(msg, ctx),
|
|
192
|
+
warn: (msg, ctx) => getLogger().warn(msg, ctx),
|
|
193
|
+
error: (msg, ctx) => getLogger().error(msg, ctx),
|
|
194
|
+
};
|
|
195
|
+
//# sourceMappingURL=logger.js.map
|