canicode 0.6.0 → 0.6.2
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/README.md +13 -4
- package/dist/cli/index.js +111 -230
- package/dist/cli/index.js.map +1 -1
- package/dist/mcp/server.js +115 -230
- package/dist/mcp/server.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp/server.js
CHANGED
|
@@ -4,210 +4,13 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
4
4
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
5
|
import { config } from 'dotenv';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import { writeFile, existsSync, mkdirSync, readFileSync } from 'fs';
|
|
7
|
+
import { writeFile, existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
8
8
|
import { exec } from 'child_process';
|
|
9
9
|
import { join, resolve, basename } from 'path';
|
|
10
10
|
import { readFile } from 'fs/promises';
|
|
11
|
+
import { randomUUID } from 'crypto';
|
|
11
12
|
import { homedir } from 'os';
|
|
12
13
|
|
|
13
|
-
var __defProp = Object.defineProperty;
|
|
14
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
-
var __esm = (fn, res) => function __init() {
|
|
16
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
17
|
-
};
|
|
18
|
-
var __export = (target, all) => {
|
|
19
|
-
for (var name in all)
|
|
20
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// src/monitoring/browser.ts
|
|
24
|
-
var browser_exports = {};
|
|
25
|
-
__export(browser_exports, {
|
|
26
|
-
initBrowserMonitoring: () => initBrowserMonitoring,
|
|
27
|
-
shutdownBrowserMonitoring: () => shutdownBrowserMonitoring,
|
|
28
|
-
trackBrowserError: () => trackBrowserError,
|
|
29
|
-
trackBrowserEvent: () => trackBrowserEvent
|
|
30
|
-
});
|
|
31
|
-
function getGlobal() {
|
|
32
|
-
return globalThis;
|
|
33
|
-
}
|
|
34
|
-
function injectScript(src) {
|
|
35
|
-
return new Promise((resolve4, reject) => {
|
|
36
|
-
const g = getGlobal();
|
|
37
|
-
const doc = g["document"];
|
|
38
|
-
if (!doc) {
|
|
39
|
-
resolve4();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const script = doc["createElement"]("script");
|
|
43
|
-
script["src"] = src;
|
|
44
|
-
script["async"] = true;
|
|
45
|
-
script["onload"] = () => resolve4();
|
|
46
|
-
script["onerror"] = () => reject(new Error(`Failed to load script: ${src}`));
|
|
47
|
-
doc["head"]["appendChild"](script);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
async function initBrowserMonitoring(config2) {
|
|
51
|
-
if (config2.enabled === false) return;
|
|
52
|
-
const g = getGlobal();
|
|
53
|
-
if (!g["document"]) return;
|
|
54
|
-
monitoringEnabled = true;
|
|
55
|
-
if (config2.posthogApiKey) {
|
|
56
|
-
try {
|
|
57
|
-
await injectScript("https://us-assets.i.posthog.com/static/array.js");
|
|
58
|
-
g["posthog"]?.["init"]?.(config2.posthogApiKey, {
|
|
59
|
-
api_host: "https://us.i.posthog.com",
|
|
60
|
-
autocapture: false,
|
|
61
|
-
capture_pageview: true
|
|
62
|
-
});
|
|
63
|
-
} catch {
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (config2.sentryDsn) {
|
|
67
|
-
try {
|
|
68
|
-
await injectScript("https://browser.sentry-cdn.com/8.0.0/bundle.min.js");
|
|
69
|
-
g["Sentry"]?.["init"]?.({
|
|
70
|
-
dsn: config2.sentryDsn,
|
|
71
|
-
environment: config2.environment ?? "web",
|
|
72
|
-
release: config2.version,
|
|
73
|
-
tracesSampleRate: 0
|
|
74
|
-
});
|
|
75
|
-
} catch {
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function trackBrowserEvent(event, properties) {
|
|
80
|
-
if (!monitoringEnabled) return;
|
|
81
|
-
try {
|
|
82
|
-
getGlobal()["posthog"]?.["capture"]?.(event, properties);
|
|
83
|
-
} catch {
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function trackBrowserError(error, context) {
|
|
87
|
-
if (!monitoringEnabled) return;
|
|
88
|
-
try {
|
|
89
|
-
getGlobal()["Sentry"]?.["captureException"]?.(
|
|
90
|
-
error,
|
|
91
|
-
context ? { extra: context } : void 0
|
|
92
|
-
);
|
|
93
|
-
} catch {
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
getGlobal()["posthog"]?.["capture"]?.("error", {
|
|
97
|
-
error: error.message,
|
|
98
|
-
...context
|
|
99
|
-
});
|
|
100
|
-
} catch {
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async function shutdownBrowserMonitoring() {
|
|
104
|
-
monitoringEnabled = false;
|
|
105
|
-
}
|
|
106
|
-
var monitoringEnabled;
|
|
107
|
-
var init_browser = __esm({
|
|
108
|
-
"src/monitoring/browser.ts"() {
|
|
109
|
-
monitoringEnabled = false;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// src/monitoring/node.ts
|
|
114
|
-
var node_exports = {};
|
|
115
|
-
__export(node_exports, {
|
|
116
|
-
initNodeMonitoring: () => initNodeMonitoring,
|
|
117
|
-
shutdownNodeMonitoring: () => shutdownNodeMonitoring,
|
|
118
|
-
trackNodeError: () => trackNodeError,
|
|
119
|
-
trackNodeEvent: () => trackNodeEvent
|
|
120
|
-
});
|
|
121
|
-
async function initNodeMonitoring(config2) {
|
|
122
|
-
if (config2.enabled === false) return;
|
|
123
|
-
monitoringEnabled2 = true;
|
|
124
|
-
commonProps = {
|
|
125
|
-
_sdk: "canicode",
|
|
126
|
-
_sdk_version: config2.version ?? "unknown",
|
|
127
|
-
_env: config2.environment ?? "unknown"
|
|
128
|
-
};
|
|
129
|
-
if (config2.posthogApiKey) {
|
|
130
|
-
try {
|
|
131
|
-
const mod = await import('posthog-node');
|
|
132
|
-
const PostHog = mod.PostHog;
|
|
133
|
-
posthogClient = new PostHog(config2.posthogApiKey, {
|
|
134
|
-
host: "https://us.i.posthog.com",
|
|
135
|
-
flushAt: 10,
|
|
136
|
-
flushInterval: 1e4
|
|
137
|
-
});
|
|
138
|
-
} catch {
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (config2.sentryDsn) {
|
|
142
|
-
try {
|
|
143
|
-
const mod = await import('@sentry/node');
|
|
144
|
-
sentryModule = mod;
|
|
145
|
-
sentryModule.init({
|
|
146
|
-
dsn: config2.sentryDsn,
|
|
147
|
-
environment: config2.environment ?? "cli",
|
|
148
|
-
release: config2.version,
|
|
149
|
-
tracesSampleRate: 0
|
|
150
|
-
});
|
|
151
|
-
} catch {
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function trackNodeEvent(event, properties) {
|
|
156
|
-
if (!monitoringEnabled2 || !posthogClient) return;
|
|
157
|
-
try {
|
|
158
|
-
const captureOpts = {
|
|
159
|
-
distinctId: "anonymous",
|
|
160
|
-
event
|
|
161
|
-
};
|
|
162
|
-
captureOpts.properties = { ...commonProps, ...properties };
|
|
163
|
-
posthogClient.capture(captureOpts);
|
|
164
|
-
} catch {
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function trackNodeError(error, context) {
|
|
168
|
-
if (!monitoringEnabled2) return;
|
|
169
|
-
try {
|
|
170
|
-
sentryModule?.captureException(error, context ? { extra: context } : void 0);
|
|
171
|
-
} catch {
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
posthogClient?.capture({
|
|
175
|
-
distinctId: "anonymous",
|
|
176
|
-
event: "cic_error",
|
|
177
|
-
properties: { ...commonProps, error: error.message, ...context }
|
|
178
|
-
});
|
|
179
|
-
} catch {
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
async function shutdownNodeMonitoring() {
|
|
183
|
-
if (!monitoringEnabled2) return;
|
|
184
|
-
const tasks = [];
|
|
185
|
-
if (posthogClient) {
|
|
186
|
-
tasks.push(
|
|
187
|
-
posthogClient.shutdown().catch(() => {
|
|
188
|
-
})
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
if (sentryModule) {
|
|
192
|
-
tasks.push(
|
|
193
|
-
sentryModule.close(2e3).catch(() => {
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
await Promise.allSettled(tasks);
|
|
198
|
-
posthogClient = null;
|
|
199
|
-
sentryModule = null;
|
|
200
|
-
monitoringEnabled2 = false;
|
|
201
|
-
}
|
|
202
|
-
var posthogClient, sentryModule, monitoringEnabled2, commonProps;
|
|
203
|
-
var init_node = __esm({
|
|
204
|
-
"src/monitoring/node.ts"() {
|
|
205
|
-
posthogClient = null;
|
|
206
|
-
sentryModule = null;
|
|
207
|
-
monitoringEnabled2 = false;
|
|
208
|
-
commonProps = {};
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
14
|
var CategorySchema = z.enum([
|
|
212
15
|
"layout",
|
|
213
16
|
"token",
|
|
@@ -1082,6 +885,10 @@ function readConfig() {
|
|
|
1082
885
|
return {};
|
|
1083
886
|
}
|
|
1084
887
|
}
|
|
888
|
+
function writeConfig(config2) {
|
|
889
|
+
ensureDir(AIREADY_DIR);
|
|
890
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(config2, null, 2) + "\n", "utf-8");
|
|
891
|
+
}
|
|
1085
892
|
function getFigmaToken() {
|
|
1086
893
|
return process.env["FIGMA_TOKEN"] ?? readConfig().figmaToken;
|
|
1087
894
|
}
|
|
@@ -1100,6 +907,14 @@ function getPosthogApiKey() {
|
|
|
1100
907
|
function getSentryDsn() {
|
|
1101
908
|
return process.env["SENTRY_DSN"] ?? readConfig().sentryDsn;
|
|
1102
909
|
}
|
|
910
|
+
function getDeviceId() {
|
|
911
|
+
const config2 = readConfig();
|
|
912
|
+
if (config2.deviceId) return config2.deviceId;
|
|
913
|
+
const id = randomUUID();
|
|
914
|
+
config2.deviceId = id;
|
|
915
|
+
writeConfig(config2);
|
|
916
|
+
return id;
|
|
917
|
+
}
|
|
1103
918
|
|
|
1104
919
|
// src/core/loader.ts
|
|
1105
920
|
function isFigmaUrl(input) {
|
|
@@ -1981,51 +1796,122 @@ var EVENTS = {
|
|
|
1981
1796
|
CLI_INIT: `${EVENT_PREFIX}cli_init`
|
|
1982
1797
|
};
|
|
1983
1798
|
|
|
1984
|
-
// src/monitoring/
|
|
1985
|
-
var
|
|
1986
|
-
|
|
1987
|
-
var
|
|
1988
|
-
|
|
1989
|
-
var
|
|
1990
|
-
function
|
|
1991
|
-
|
|
1992
|
-
|
|
1799
|
+
// src/monitoring/capture.ts
|
|
1800
|
+
var monitoringEnabled = false;
|
|
1801
|
+
var posthogApiKey;
|
|
1802
|
+
var sentryDsn;
|
|
1803
|
+
var distinctId = "anonymous";
|
|
1804
|
+
var commonProps = {};
|
|
1805
|
+
function uuid4() {
|
|
1806
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
1807
|
+
const r = Math.random() * 16 | 0;
|
|
1808
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
1809
|
+
return v.toString(16);
|
|
1810
|
+
});
|
|
1993
1811
|
}
|
|
1994
|
-
|
|
1812
|
+
function parseSentryDsn(dsn) {
|
|
1813
|
+
try {
|
|
1814
|
+
const url = new URL(dsn);
|
|
1815
|
+
const key = url.username;
|
|
1816
|
+
const projectId = url.pathname.slice(1);
|
|
1817
|
+
const host = url.protocol + "//" + url.host;
|
|
1818
|
+
if (!key || !projectId) return null;
|
|
1819
|
+
return { key, host, projectId };
|
|
1820
|
+
} catch {
|
|
1821
|
+
return null;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
function initCapture(config2) {
|
|
1995
1825
|
if (config2.enabled === false) return;
|
|
1996
1826
|
if (!config2.posthogApiKey && !config2.sentryDsn) return;
|
|
1827
|
+
monitoringEnabled = true;
|
|
1828
|
+
posthogApiKey = config2.posthogApiKey;
|
|
1829
|
+
sentryDsn = config2.sentryDsn;
|
|
1830
|
+
distinctId = config2.distinctId ?? "anonymous";
|
|
1831
|
+
commonProps = {
|
|
1832
|
+
_sdk: "canicode",
|
|
1833
|
+
_sdk_version: config2.version ?? "unknown",
|
|
1834
|
+
_env: config2.environment ?? "unknown"
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
function captureEvent(event, properties) {
|
|
1838
|
+
if (!monitoringEnabled || !posthogApiKey) return;
|
|
1997
1839
|
try {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
}
|
|
1840
|
+
fetch("https://us.i.posthog.com/i/v0/e/", {
|
|
1841
|
+
method: "POST",
|
|
1842
|
+
headers: { "Content-Type": "application/json" },
|
|
1843
|
+
body: JSON.stringify({
|
|
1844
|
+
api_key: posthogApiKey,
|
|
1845
|
+
event,
|
|
1846
|
+
distinct_id: distinctId,
|
|
1847
|
+
properties: { ...commonProps, ...properties },
|
|
1848
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1849
|
+
})
|
|
1850
|
+
}).catch(() => {
|
|
1851
|
+
});
|
|
2011
1852
|
} catch {
|
|
2012
1853
|
}
|
|
2013
1854
|
}
|
|
1855
|
+
function captureError(error, context) {
|
|
1856
|
+
if (!monitoringEnabled) return;
|
|
1857
|
+
if (sentryDsn) {
|
|
1858
|
+
const parsed = parseSentryDsn(sentryDsn);
|
|
1859
|
+
if (parsed) {
|
|
1860
|
+
try {
|
|
1861
|
+
const eventId = uuid4();
|
|
1862
|
+
const envelope = [
|
|
1863
|
+
JSON.stringify({ event_id: eventId, sent_at: (/* @__PURE__ */ new Date()).toISOString(), dsn: sentryDsn }),
|
|
1864
|
+
JSON.stringify({ type: "event", content_type: "application/json" }),
|
|
1865
|
+
JSON.stringify({
|
|
1866
|
+
event_id: eventId,
|
|
1867
|
+
exception: { values: [{ type: error.name, value: error.message }] },
|
|
1868
|
+
platform: "node",
|
|
1869
|
+
timestamp: Date.now() / 1e3,
|
|
1870
|
+
extra: context
|
|
1871
|
+
})
|
|
1872
|
+
].join("\n");
|
|
1873
|
+
fetch(`${parsed.host}/api/${parsed.projectId}/envelope/`, {
|
|
1874
|
+
method: "POST",
|
|
1875
|
+
headers: {
|
|
1876
|
+
"Content-Type": "application/x-sentry-envelope",
|
|
1877
|
+
"X-Sentry-Auth": `Sentry sentry_version=7, sentry_key=${parsed.key}`
|
|
1878
|
+
},
|
|
1879
|
+
body: envelope
|
|
1880
|
+
}).catch(() => {
|
|
1881
|
+
});
|
|
1882
|
+
} catch {
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
captureEvent("cic_error", { error: error.message, ...context });
|
|
1887
|
+
}
|
|
1888
|
+
function shutdownCapture() {
|
|
1889
|
+
monitoringEnabled = false;
|
|
1890
|
+
posthogApiKey = void 0;
|
|
1891
|
+
sentryDsn = void 0;
|
|
1892
|
+
distinctId = "anonymous";
|
|
1893
|
+
commonProps = {};
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
// src/monitoring/index.ts
|
|
1897
|
+
function initMonitoring(config2) {
|
|
1898
|
+
initCapture(config2);
|
|
1899
|
+
}
|
|
2014
1900
|
function trackEvent(event, properties) {
|
|
2015
1901
|
try {
|
|
2016
|
-
|
|
1902
|
+
captureEvent(event, properties);
|
|
2017
1903
|
} catch {
|
|
2018
1904
|
}
|
|
2019
1905
|
}
|
|
2020
1906
|
function trackError(error, context) {
|
|
2021
1907
|
try {
|
|
2022
|
-
|
|
1908
|
+
captureError(error, context);
|
|
2023
1909
|
} catch {
|
|
2024
1910
|
}
|
|
2025
1911
|
}
|
|
2026
|
-
|
|
1912
|
+
function shutdownMonitoring() {
|
|
2027
1913
|
try {
|
|
2028
|
-
|
|
1914
|
+
shutdownCapture();
|
|
2029
1915
|
} catch {
|
|
2030
1916
|
}
|
|
2031
1917
|
}
|
|
@@ -3454,14 +3340,13 @@ async function main() {
|
|
|
3454
3340
|
monitoringConfig.posthogApiKey = phKey;
|
|
3455
3341
|
const sDsn = getSentryDsn() || SENTRY_DSN;
|
|
3456
3342
|
monitoringConfig.sentryDsn = sDsn;
|
|
3457
|
-
|
|
3458
|
-
|
|
3343
|
+
monitoringConfig.distinctId = getDeviceId();
|
|
3344
|
+
initMonitoring(monitoringConfig);
|
|
3459
3345
|
const transport = new StdioServerTransport();
|
|
3460
3346
|
await server.connect(transport);
|
|
3461
3347
|
}
|
|
3462
3348
|
process.on("beforeExit", () => {
|
|
3463
|
-
shutdownMonitoring()
|
|
3464
|
-
});
|
|
3349
|
+
shutdownMonitoring();
|
|
3465
3350
|
});
|
|
3466
3351
|
main().catch(console.error);
|
|
3467
3352
|
//# sourceMappingURL=server.js.map
|