@canonry/canonry 7.51.5 → 7.51.6

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 (116) hide show
  1. package/dist/ads-ABAT3K4K.js +544 -0
  2. package/dist/agent-5G4DRLYX.js +70 -0
  3. package/dist/agent-ask-UDVCZRO7.js +139 -0
  4. package/dist/agent-conversations-5E4JP2QZ.js +52 -0
  5. package/dist/agent-memory-7IIJ4HGZ.js +92 -0
  6. package/dist/agent-providers-BOXPUXZ4.js +55 -0
  7. package/dist/agent-transcript-4O56G6PQ.js +77 -0
  8. package/dist/analytics-PKMWX5XL.js +240 -0
  9. package/dist/apply-OK4XEBDA.js +175 -0
  10. package/dist/backfill-2OT56CX2.js +41 -0
  11. package/dist/backlinks-547WCHND.js +303 -0
  12. package/dist/bing-ZVBV4ZD5.js +418 -0
  13. package/dist/bootstrap-HUB7XQ73.js +326 -0
  14. package/dist/cdp-KQKQ4PWJ.js +162 -0
  15. package/dist/chunk-2G6IP3MO.js +517 -0
  16. package/dist/chunk-42D2LE2B.js +1273 -0
  17. package/dist/chunk-4MJYGB56.js +124 -0
  18. package/dist/chunk-63ISSSGX.js +9150 -0
  19. package/dist/{chunk-PLYJX67A.js → chunk-6G6FTDWC.js} +8080 -13939
  20. package/dist/chunk-6GO5VVAC.js +15 -0
  21. package/dist/{chunk-4YCGZGA3.js → chunk-73P65KPW.js} +2 -2
  22. package/dist/chunk-7B2Q4NJE.js +133 -0
  23. package/dist/{chunk-JBZZEIM2.js → chunk-7WZ2FPB4.js} +2 -13
  24. package/dist/chunk-AOJU5LKX.js +8 -0
  25. package/dist/chunk-B2FR2ZQ4.js +420 -0
  26. package/dist/{chunk-HAHXPJQ5.js → chunk-B5J675KK.js} +16 -1684
  27. package/dist/{chunk-SFMWHPMX.js → chunk-D6COIM3U.js} +17128 -17143
  28. package/dist/{chunk-A3WSAAQS.js → chunk-DGVUTH7W.js} +9086 -34522
  29. package/dist/chunk-ELCLGWUT.js +83 -0
  30. package/dist/chunk-GO2J7SYT.js +1034 -0
  31. package/dist/chunk-HACZUMGM.js +145 -0
  32. package/dist/chunk-HM4NNKLG.js +94 -0
  33. package/dist/chunk-I3A56PFP.js +58 -0
  34. package/dist/chunk-I77PLCWG.js +961 -0
  35. package/dist/chunk-ISOQPVPY.js +232 -0
  36. package/dist/chunk-KFT5LOP2.js +610 -0
  37. package/dist/chunk-MLKGABMK.js +9 -0
  38. package/dist/chunk-MMEO22MF.js +38 -0
  39. package/dist/chunk-NHQ2U5I4.js +78 -0
  40. package/dist/chunk-PCXRFT3N.js +530 -0
  41. package/dist/chunk-PITHTCAX.js +15376 -0
  42. package/dist/chunk-QWKPSFGL.js +30 -0
  43. package/dist/chunk-RKIXES2B.js +609 -0
  44. package/dist/chunk-TSENU4GG.js +18 -0
  45. package/dist/{chunk-HLVEB5TB.js → chunk-TUTKNUMV.js} +7 -5
  46. package/dist/chunk-U3AHE2RT.js +1160 -0
  47. package/dist/chunk-UQ3MOZGC.js +644 -0
  48. package/dist/{chunk-AZFPA7JV.js → chunk-VBCE4CLX.js} +6 -4
  49. package/dist/chunk-VJWDBFSL.js +69 -0
  50. package/dist/chunk-VYMZ3QXG.js +8264 -0
  51. package/dist/chunk-WAULJDKO.js +2686 -0
  52. package/dist/chunk-WDFI5YMD.js +204 -0
  53. package/dist/chunk-XEBKF4N5.js +8 -0
  54. package/dist/chunk-Z7IUAJOF.js +13 -0
  55. package/dist/{chunk-KEATAHXH.js → chunk-ZWJRY5UI.js} +358 -581
  56. package/dist/chunk-ZXUAWVWM.js +15 -0
  57. package/dist/citations-UYB2RU5U.js +106 -0
  58. package/dist/{cli-catalog-MO6Z2CIZ.js → cli-catalog-F6FI7NB2.js} +5 -3
  59. package/dist/cli-commands-ZG5ILKDA.js +19 -0
  60. package/dist/cli.js +35 -29
  61. package/dist/competitor-EKP4R7YY.js +561 -0
  62. package/dist/content-DREE6JF3.js +257 -0
  63. package/dist/dashboard-ZALEOLLU.js +71 -0
  64. package/dist/demo-JG4Y22O4.js +75 -0
  65. package/dist/{demo-server-GIWDJGJX.js → demo-server-3A4J2C65.js} +22 -9
  66. package/dist/discover-W6GMD2HS.js +372 -0
  67. package/dist/discover-eval-CKFZHRBW.js +282 -0
  68. package/dist/doctor-TNGBSUMA.js +152 -0
  69. package/dist/evidence-3H2GFQBZ.js +57 -0
  70. package/dist/export-cmd-WUIKU5GK.js +49 -0
  71. package/dist/ga-JI6REFO4.js +911 -0
  72. package/dist/gbp-4ENDM5NS.js +370 -0
  73. package/dist/google-HKQSCLOC.js +946 -0
  74. package/dist/google-marketing-KQR5J2S4.js +403 -0
  75. package/dist/health-cmd-TS7EMMCS.js +64 -0
  76. package/dist/history-MSD5DK6K.js +90 -0
  77. package/dist/index.d.ts +47 -47
  78. package/dist/index.js +29 -6
  79. package/dist/init-L6WAEOWX.js +432 -0
  80. package/dist/insights-RTZ3IZTD.js +63 -0
  81. package/dist/intelligence-service-TH52PCNJ.js +15 -0
  82. package/dist/keys-625DZBRM.js +116 -0
  83. package/dist/keyword-CW46RNRR.js +164 -0
  84. package/dist/logs-V33SHBIW.js +30 -0
  85. package/dist/mcp-DFEDPSEG.js +14 -0
  86. package/dist/mcp.js +14 -5
  87. package/dist/measurement-plan-6W37RUOP.js +42 -0
  88. package/dist/notify-DSUOT7WO.js +125 -0
  89. package/dist/organic-evidence-BMN6L4OB.js +53 -0
  90. package/dist/overview-WRRMBZ6S.js +213 -0
  91. package/dist/project-2GJIU3FE.js +460 -0
  92. package/dist/query-3XPMGJUA.js +211 -0
  93. package/dist/research-V433CKJ4.js +200 -0
  94. package/dist/results-export-RGBU7QQQ.js +27 -0
  95. package/dist/run-NIAC6OJN.js +31 -0
  96. package/dist/schedule-KDWXRIE7.js +177 -0
  97. package/dist/search-626MPUJN.js +42 -0
  98. package/dist/serve-73SMMASI.js +557 -0
  99. package/dist/session-7WWOETZB.js +47 -0
  100. package/dist/settings-VKFQO6F2.js +107 -0
  101. package/dist/skills-5HC5H7TE.js +33 -0
  102. package/dist/snapshot-BSJUHFBC.js +538 -0
  103. package/dist/src-F6HM73TN.js +316 -0
  104. package/dist/status-V4OWP7LZ.js +126 -0
  105. package/dist/support-ARF4HER7.js +24 -0
  106. package/dist/technical-aeo-TG7CGU3F.js +625 -0
  107. package/dist/telemetry-O2IUNUBW.js +118 -0
  108. package/dist/tools-2GJIDKND.js +41 -0
  109. package/dist/traffic-XV4I3UPH.js +1295 -0
  110. package/dist/users-VGBLDL5K.js +170 -0
  111. package/dist/visibility-stats-UKJYJ6PP.js +241 -0
  112. package/dist/wordpress-JZA7CGC6.js +600 -0
  113. package/package.json +1 -1
  114. package/dist/chunk-4QQYYRHV.js +0 -23082
  115. package/dist/cli-commands-FOJR3HHU.js +0 -15
  116. package/dist/intelligence-service-XQCNWAPL.js +0 -9
@@ -0,0 +1,30 @@
1
+ import {
2
+ API_PROVIDER_NAMES,
3
+ ProviderNames
4
+ } from "./chunk-D6COIM3U.js";
5
+
6
+ // src/provider-registration.ts
7
+ function isApiProviderRegistrable(name, entry) {
8
+ if (!entry) return false;
9
+ if (name === ProviderNames.local) return Boolean(entry.baseUrl);
10
+ if (name === ProviderNames.gemini) return Boolean(entry.apiKey || entry.vertexProject);
11
+ return Boolean(entry.apiKey);
12
+ }
13
+ function isCdpProviderRegistrable(cdp) {
14
+ return Boolean(cdp?.host || cdp?.port);
15
+ }
16
+ function registeredProviderNames(config) {
17
+ const names = API_PROVIDER_NAMES.filter((name) => {
18
+ const entry = config.providers?.[name];
19
+ if (name === ProviderNames.gemini && !entry && config.geminiApiKey) return true;
20
+ return isApiProviderRegistrable(name, entry);
21
+ });
22
+ if (isCdpProviderRegistrable(config.cdp)) names.push(ProviderNames.cdpChatgpt);
23
+ return names;
24
+ }
25
+
26
+ export {
27
+ isApiProviderRegistrable,
28
+ isCdpProviderRegistrable,
29
+ registeredProviderNames
30
+ };
@@ -0,0 +1,609 @@
1
+ import {
2
+ configExists,
3
+ getConfigDir,
4
+ getConfigPath,
5
+ loadConfig,
6
+ loadConfigRaw,
7
+ saveConfigPatch
8
+ } from "./chunk-UQ3MOZGC.js";
9
+ import {
10
+ CANONRY_NPM_PACKAGE_URL,
11
+ compareSemver,
12
+ detectAgentRuntime,
13
+ isGhostTelemetryEvent,
14
+ isInstallMethod,
15
+ isStrictSemver,
16
+ maskTelemetryAnonymousId,
17
+ normalizeInstallRef,
18
+ updateCheckEnvOptOut,
19
+ upgradeCaveatFor,
20
+ upgradeCommandFor
21
+ } from "./chunk-D6COIM3U.js";
22
+
23
+ // src/runtime-context.ts
24
+ function cliRuntimeContext(env = process.env, stdio = process) {
25
+ return {
26
+ agent: detectAgentRuntime(env),
27
+ interactive: Boolean(stdio.stdin.isTTY && stdio.stdout.isTTY)
28
+ };
29
+ }
30
+
31
+ // src/update-check.ts
32
+ import fs from "fs";
33
+ import { createRequire } from "module";
34
+ import { fileURLToPath } from "url";
35
+ var _require = createRequire(import.meta.url);
36
+ var { version: PKG_VERSION } = _require("../package.json");
37
+ var PKG_NAME = "@canonry/canonry";
38
+ var NPM_DIST_TAGS_URL = `https://registry.npmjs.org/-/package/${PKG_NAME}/dist-tags`;
39
+ var NPM_PACKAGE_URL = CANONRY_NPM_PACKAGE_URL;
40
+ var FETCH_TIMEOUT_MS = 1500;
41
+ var CONTAINER_MARKERS = ["/.dockerenv", "/run/.containerenv"];
42
+ function detectInstallMethod(opts) {
43
+ const declared = (opts?.env ?? process.env).CANONRY_INSTALL_METHOD;
44
+ if (isInstallMethod(declared)) return declared;
45
+ let modulePath = opts?.modulePath ?? fileURLToPath(import.meta.url);
46
+ try {
47
+ modulePath = fs.realpathSync(modulePath);
48
+ } catch {
49
+ }
50
+ if (modulePath.replace(/\\/g, "/").includes("/Cellar/canonry/")) return "homebrew";
51
+ const exists = opts?.exists ?? fs.existsSync;
52
+ if (CONTAINER_MARKERS.some((marker) => exists(marker))) return "docker";
53
+ return "npm";
54
+ }
55
+ var detectedInstallMethod;
56
+ function currentInstallMethod() {
57
+ detectedInstallMethod ??= detectInstallMethod();
58
+ return detectedInstallMethod;
59
+ }
60
+ function isUpdateCheckEnabled() {
61
+ return updateCheckDisabledReason() === null;
62
+ }
63
+ function updateCheckDisabledReason() {
64
+ const envOptOut = updateCheckEnvOptOut(process.env);
65
+ if (envOptOut) return envOptOut;
66
+ if (!configExists()) return null;
67
+ try {
68
+ return loadConfigRaw()?.updateCheck === false ? "config" : null;
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+ async function fetchLatestVersion(opts) {
74
+ const controller = new AbortController();
75
+ const timeout = setTimeout(() => controller.abort(), opts?.timeoutMs ?? FETCH_TIMEOUT_MS);
76
+ timeout.unref();
77
+ try {
78
+ const res = await fetch(NPM_DIST_TAGS_URL, {
79
+ signal: controller.signal,
80
+ headers: { accept: "application/json" }
81
+ });
82
+ if (!res.ok) return null;
83
+ const data = await res.json();
84
+ if (typeof data.latest !== "string" || !isStrictSemver(data.latest)) return null;
85
+ return data.latest;
86
+ } catch {
87
+ return null;
88
+ } finally {
89
+ clearTimeout(timeout);
90
+ }
91
+ }
92
+ function buildUpdateAvailable(current, latest, installMethod = currentInstallMethod()) {
93
+ if (!isStrictSemver(latest)) return null;
94
+ if (compareSemver(latest, current) <= 0) return null;
95
+ return {
96
+ current,
97
+ latest,
98
+ url: NPM_PACKAGE_URL,
99
+ upgradeCommand: upgradeCommandFor(installMethod),
100
+ installMethod
101
+ };
102
+ }
103
+ async function checkLatestVersionForCli(opts) {
104
+ if (!isUpdateCheckEnabled()) return null;
105
+ if (!configExists()) return null;
106
+ const now = opts?.now ? opts.now() : /* @__PURE__ */ new Date();
107
+ const ttlMs = (opts?.ttlHours ?? 24) * 60 * 60 * 1e3;
108
+ let raw;
109
+ try {
110
+ raw = loadConfigRaw();
111
+ } catch {
112
+ return null;
113
+ }
114
+ if (!raw) return null;
115
+ const lastCheckedAt = raw.lastUpdateCheckAt ? Date.parse(raw.lastUpdateCheckAt) : NaN;
116
+ const cachedLatest = typeof raw.lastKnownLatestVersion === "string" ? raw.lastKnownLatestVersion : void 0;
117
+ if (Number.isFinite(lastCheckedAt) && now.getTime() - lastCheckedAt < ttlMs) {
118
+ if (!cachedLatest) return null;
119
+ return buildUpdateAvailable(PKG_VERSION, cachedLatest);
120
+ }
121
+ const latest = await fetchLatestVersion();
122
+ if (!latest) {
123
+ try {
124
+ saveConfigPatch({ lastUpdateCheckAt: now.toISOString() });
125
+ } catch {
126
+ }
127
+ return null;
128
+ }
129
+ try {
130
+ saveConfigPatch({
131
+ lastUpdateCheckAt: now.toISOString(),
132
+ lastKnownLatestVersion: latest
133
+ });
134
+ } catch {
135
+ }
136
+ return buildUpdateAvailable(PKG_VERSION, latest);
137
+ }
138
+ function readCachedUpdateAvailable() {
139
+ if (!isUpdateCheckEnabled()) return null;
140
+ if (!configExists()) return null;
141
+ try {
142
+ const cachedLatest = loadConfigRaw()?.lastKnownLatestVersion;
143
+ if (typeof cachedLatest !== "string") return null;
144
+ return buildUpdateAvailable(PKG_VERSION, cachedLatest);
145
+ } catch {
146
+ return null;
147
+ }
148
+ }
149
+ var printedUpdateAvailable = null;
150
+ function notePrintedUpdateAvailable(update) {
151
+ printedUpdateAvailable = update;
152
+ }
153
+ function getPrintedUpdateAvailable() {
154
+ return printedUpdateAvailable;
155
+ }
156
+ var UPDATE_AVAILABLE_NOTICE_CODE = "UPDATE_AVAILABLE";
157
+ function formatUpdateNotice(update, opts) {
158
+ const caveat = upgradeCaveatFor(update.installMethod);
159
+ if (opts.format === "json" || opts.format === "jsonl") {
160
+ return `${JSON.stringify({
161
+ notice: {
162
+ code: UPDATE_AVAILABLE_NOTICE_CODE,
163
+ current: update.current,
164
+ latest: update.latest,
165
+ installMethod: update.installMethod,
166
+ upgradeCommand: update.upgradeCommand,
167
+ url: update.url,
168
+ ...caveat ? { note: caveat } : {}
169
+ }
170
+ })}
171
+ `;
172
+ }
173
+ if (opts.interactive) {
174
+ return `
175
+ \u2192 canonry ${update.latest} is available (you have ${update.current}).
176
+ Upgrade: ${update.upgradeCommand}
177
+ ` + (caveat ? ` ${caveat}
178
+ ` : "") + "\n";
179
+ }
180
+ const upgrade = update.installMethod === "docker" ? `Upgrade: ${update.upgradeCommand}.` : `Upgrade with \`${update.upgradeCommand}\`, then restart any running \`canonry serve\`.`;
181
+ return `[canonry] ${UPDATE_AVAILABLE_NOTICE_CODE}: canonry ${update.latest} is available (installed ${update.current}). ${upgrade} ${caveat ? `${caveat} ` : ""}Silence with CANONRY_DISABLE_UPDATE_CHECK=1.
182
+ `;
183
+ }
184
+ var memoryCache = null;
185
+ var inFlight = null;
186
+ function startBackgroundRefresh(getNow) {
187
+ if (inFlight) return;
188
+ inFlight = (async () => {
189
+ try {
190
+ const latest = await fetchLatestVersion();
191
+ memoryCache = { fetchedAt: getNow(), latest };
192
+ } catch {
193
+ memoryCache = { fetchedAt: getNow(), latest: null };
194
+ } finally {
195
+ inFlight = null;
196
+ }
197
+ })();
198
+ }
199
+ function checkLatestVersionForServer(opts) {
200
+ if (opts?.storedOnly) return memoryCache?.latest ? buildUpdateAvailable(PKG_VERSION, memoryCache.latest) : null;
201
+ if (!isUpdateCheckEnabled()) return null;
202
+ const getNow = opts?.now ?? Date.now;
203
+ const ttl = opts?.ttlMs ?? 60 * 60 * 1e3;
204
+ const now = getNow();
205
+ if (!memoryCache || now - memoryCache.fetchedAt >= ttl) {
206
+ startBackgroundRefresh(getNow);
207
+ }
208
+ if (!memoryCache || !memoryCache.latest) return null;
209
+ return buildUpdateAvailable(PKG_VERSION, memoryCache.latest);
210
+ }
211
+ function getServerUpdateStatus(opts) {
212
+ const installMethod = currentInstallMethod();
213
+ const base = { current: PKG_VERSION, installMethod, upgradeCommand: upgradeCommandFor(installMethod), url: NPM_PACKAGE_URL };
214
+ const disabledBy = updateCheckDisabledReason();
215
+ if (disabledBy) return { ...base, enabled: false, disabledBy, latest: null };
216
+ checkLatestVersionForServer(opts);
217
+ let latest = memoryCache?.latest ?? null;
218
+ if (!latest && configExists()) {
219
+ try {
220
+ const cached2 = loadConfigRaw()?.lastKnownLatestVersion;
221
+ if (typeof cached2 === "string") latest = cached2;
222
+ } catch {
223
+ }
224
+ }
225
+ return { ...base, enabled: true, latest: latest && isStrictSemver(latest) ? latest : null };
226
+ }
227
+
228
+ // src/telemetry-environment.ts
229
+ import fs2 from "fs";
230
+ import os from "os";
231
+ import path from "path";
232
+ import { createRequire as createRequire2 } from "module";
233
+ var _require2 = createRequire2(import.meta.url);
234
+ function packageRoot() {
235
+ try {
236
+ return path.dirname(_require2.resolve("../package.json"));
237
+ } catch {
238
+ return void 0;
239
+ }
240
+ }
241
+ function realpath(p) {
242
+ try {
243
+ return fs2.realpathSync(p);
244
+ } catch {
245
+ return path.resolve(p);
246
+ }
247
+ }
248
+ function detectTelemetryEnvironment(opts = {}) {
249
+ const env = opts.env ?? process.env;
250
+ const exists = opts.exists ?? fs2.existsSync;
251
+ const flags = [];
252
+ if (detectInstallMethod({ env, exists }) === "docker" || env.KUBERNETES_SERVICE_HOST) flags.push("container");
253
+ const configDir = opts.configDir ?? getConfigDir();
254
+ const configForms = [path.resolve(configDir), realpath(configDir)];
255
+ const tmpForms = (opts.tmpDirs ?? [os.tmpdir(), "/tmp", "/private/tmp", "/var/tmp"]).flatMap((dir) => [path.resolve(dir), realpath(dir)]);
256
+ const underTmp = configForms.some((c) => tmpForms.some((t) => c === t || c.startsWith(`${t}${path.sep}`)));
257
+ if (underTmp) flags.push("temp_config");
258
+ const root = opts.root ?? packageRoot();
259
+ if (root && exists(path.join(root, "..", "..", "pnpm-workspace.yaml"))) flags.push("dev_build");
260
+ if (env.CANONRY_TELEMETRY_SOURCE === "wp-plugin") flags.push("wp_subprocess");
261
+ return flags;
262
+ }
263
+ var cached;
264
+ function telemetryEnvironment() {
265
+ cached ??= detectTelemetryEnvironment();
266
+ return cached;
267
+ }
268
+ function installSource() {
269
+ return telemetryEnvironment().includes("dev_build") ? "source" : detectInstallMethod();
270
+ }
271
+ function recordInstallRef(ref, env = process.env) {
272
+ const value = normalizeInstallRef(ref ?? env.CANONRY_REF);
273
+ if (!value) return;
274
+ try {
275
+ const raw = loadConfigRaw();
276
+ if (!raw || raw.installRef) return;
277
+ saveConfigPatch({ installRef: value });
278
+ } catch {
279
+ }
280
+ }
281
+ function installAttribution() {
282
+ let installRef;
283
+ try {
284
+ installRef = normalizeInstallRef(loadConfigRaw()?.installRef);
285
+ } catch {
286
+ installRef = void 0;
287
+ }
288
+ return installRef ? { installSource: installSource(), installRef } : { installSource: installSource() };
289
+ }
290
+
291
+ // src/telemetry.ts
292
+ import crypto from "crypto";
293
+ import fs3 from "fs";
294
+ import os2 from "os";
295
+ import path2 from "path";
296
+ import { createRequire as createRequire3 } from "module";
297
+ var _require3 = createRequire3(import.meta.url);
298
+ var { version: VERSION } = _require3("../package.json");
299
+ var TELEMETRY_ENDPOINT = "https://canonry.ai/api/telemetry";
300
+ var TIMEOUT_MS = 3e3;
301
+ var ANON_ID_ENV_VAR = "CANONRY_ANONYMOUS_ID";
302
+ var ANON_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
303
+ function bucketCliCommandDuration(durationMs) {
304
+ const duration = Number.isFinite(durationMs) ? Math.max(0, durationMs) : 0;
305
+ if (duration < 1e3) return "under_1s";
306
+ if (duration < 1e4) return "1s_to_10s";
307
+ if (duration < 6e4) return "10s_to_1m";
308
+ if (duration < 3e5) return "1m_to_5m";
309
+ if (duration < 18e5) return "5m_to_30m";
310
+ return "30m_or_more";
311
+ }
312
+ function trackCliCommandFinished(input) {
313
+ trackEvent(
314
+ "cli.command.finished",
315
+ {
316
+ command: input.command,
317
+ success: input.success,
318
+ duration_bucket: bucketCliCommandDuration(input.durationMs),
319
+ ...input.setupState ? { setup_state: input.setupState } : {},
320
+ ...cliRuntimeContext()
321
+ },
322
+ input.errorCode ? { errorCode: input.errorCode } : void 0
323
+ );
324
+ }
325
+ var SESSION_ID = crypto.randomUUID();
326
+ var CURRENT_SOURCE = "cli";
327
+ var TELEMETRY_SOURCE_VALUES = /* @__PURE__ */ new Set([
328
+ "cli",
329
+ "cli-server",
330
+ "api",
331
+ "mcp-server",
332
+ "wp-plugin",
333
+ "dashboard",
334
+ "agent-runtime"
335
+ ]);
336
+ function envSourceOverride() {
337
+ const raw = process.env.CANONRY_TELEMETRY_SOURCE?.trim();
338
+ return raw && TELEMETRY_SOURCE_VALUES.has(raw) ? raw : void 0;
339
+ }
340
+ function setTelemetrySource(source) {
341
+ CURRENT_SOURCE = source;
342
+ }
343
+ function resolveTelemetryStatus(input) {
344
+ const base = {
345
+ configuredEnabled: input.configuredEnabled,
346
+ ...input.anonymousId ? { anonymousId: maskTelemetryAnonymousId(input.anonymousId) } : {},
347
+ target: "local"
348
+ };
349
+ if (input.canonryTelemetryDisabled === "1") {
350
+ return { ...base, enabled: false, reason: "CANONRY_TELEMETRY_DISABLED" };
351
+ }
352
+ if (input.doNotTrack === "1") {
353
+ return { ...base, enabled: false, reason: "DO_NOT_TRACK" };
354
+ }
355
+ if (input.ci) return { ...base, enabled: false, reason: "CI" };
356
+ if (!input.configuredEnabled) return { ...base, enabled: false, reason: "configured_disabled" };
357
+ if (input.configState === "absent") return { ...base, enabled: true, reason: "NO_CONFIG" };
358
+ if (input.configState === "unavailable") return { ...base, enabled: true, reason: "CONFIG_UNAVAILABLE" };
359
+ return { ...base, enabled: true, reason: "enabled" };
360
+ }
361
+ function getTelemetryStatus() {
362
+ const env = {
363
+ canonryTelemetryDisabled: process.env.CANONRY_TELEMETRY_DISABLED,
364
+ doNotTrack: process.env.DO_NOT_TRACK,
365
+ ci: process.env.CI
366
+ };
367
+ if (!configExists()) {
368
+ return resolveTelemetryStatus({ ...env, configuredEnabled: true, configState: "absent" });
369
+ }
370
+ try {
371
+ const config = loadConfig();
372
+ return resolveTelemetryStatus({
373
+ ...env,
374
+ configuredEnabled: config.telemetry !== false,
375
+ configState: "present",
376
+ anonymousId: config.anonymousId
377
+ });
378
+ } catch {
379
+ return resolveTelemetryStatus({ ...env, configuredEnabled: true, configState: "unavailable" });
380
+ }
381
+ }
382
+ function isTelemetryEnabled() {
383
+ return getTelemetryStatus().enabled;
384
+ }
385
+ function getOrCreateAnonymousId() {
386
+ const fromEnv = readEnvAnonymousId();
387
+ if (fromEnv) return fromEnv;
388
+ if (configExists()) {
389
+ try {
390
+ const config = loadConfig();
391
+ if (config.anonymousId) return config.anonymousId;
392
+ const carried = preConfigAnonymousId?.configPath === getConfigPath() ? preConfigAnonymousId.id : void 0;
393
+ const id = carried ?? crypto.randomUUID();
394
+ config.anonymousId = id;
395
+ try {
396
+ saveConfigPatch(config);
397
+ } catch {
398
+ return getDeterministicAnonymousId();
399
+ }
400
+ return id;
401
+ } catch {
402
+ return getDeterministicAnonymousId();
403
+ }
404
+ }
405
+ const fallback = getDeterministicAnonymousId();
406
+ if (fallback) preConfigAnonymousId = { configPath: getConfigPath(), id: fallback };
407
+ return fallback;
408
+ }
409
+ var preConfigAnonymousId;
410
+ function readEnvAnonymousId() {
411
+ const raw = process.env[ANON_ID_ENV_VAR]?.trim();
412
+ if (!raw) return void 0;
413
+ if (!ANON_ID_PATTERN.test(raw)) {
414
+ return void 0;
415
+ }
416
+ return raw.toLowerCase();
417
+ }
418
+ function getDeterministicAnonymousId() {
419
+ return hostDerivedId("canonry-anon");
420
+ }
421
+ function hostDerivedId(prefix) {
422
+ try {
423
+ const hostname = os2.hostname() || "";
424
+ const mac = firstNonInternalMac();
425
+ const seed = `${prefix}:${hostname}:${mac}`;
426
+ const hex = crypto.createHash("sha256").update(seed).digest("hex");
427
+ const a = hex.slice(0, 8);
428
+ const b = hex.slice(8, 12);
429
+ const c = "5" + hex.slice(13, 16);
430
+ const dHi = (parseInt(hex.slice(16, 18), 16) & 63 | 128).toString(16).padStart(2, "0");
431
+ const d = dHi + hex.slice(18, 20);
432
+ const e = hex.slice(20, 32);
433
+ return `${a}-${b}-${c}-${d}-${e}`;
434
+ } catch {
435
+ return void 0;
436
+ }
437
+ }
438
+ var machineId;
439
+ function getMachineId() {
440
+ machineId ??= {
441
+ value: resolveMachineId({
442
+ filePath: path2.join(os2.homedir(), ".canonry", "machine-id"),
443
+ inContainer: telemetryEnvironment().includes("container"),
444
+ derive: () => hostDerivedId("canonry-machine")
445
+ })
446
+ };
447
+ return machineId.value;
448
+ }
449
+ function resolveMachineId(opts) {
450
+ if (opts.inContainer) return void 0;
451
+ const saved = readMachineIdFile(opts.filePath);
452
+ if (saved) return saved;
453
+ const derived = opts.derive();
454
+ if (!derived) return void 0;
455
+ try {
456
+ fs3.mkdirSync(path2.dirname(opts.filePath), { recursive: true });
457
+ fs3.writeFileSync(opts.filePath, `${derived}
458
+ `, { flag: "wx" });
459
+ return derived;
460
+ } catch {
461
+ return readMachineIdFile(opts.filePath) ?? derived;
462
+ }
463
+ }
464
+ function readMachineIdFile(filePath) {
465
+ try {
466
+ const value = fs3.readFileSync(filePath, "utf8").trim().toLowerCase();
467
+ return ANON_ID_PATTERN.test(value) ? value : void 0;
468
+ } catch {
469
+ return void 0;
470
+ }
471
+ }
472
+ function firstNonInternalMac() {
473
+ try {
474
+ const interfaces = os2.networkInterfaces();
475
+ for (const ifaces of Object.values(interfaces)) {
476
+ if (!ifaces) continue;
477
+ for (const iface of ifaces) {
478
+ if (iface.internal) continue;
479
+ if (!iface.mac || iface.mac === "00:00:00:00:00:00") continue;
480
+ return iface.mac;
481
+ }
482
+ }
483
+ } catch {
484
+ }
485
+ return "no-mac";
486
+ }
487
+ function isFirstRun() {
488
+ if (!configExists()) return false;
489
+ try {
490
+ const config = loadConfig();
491
+ return !config.anonymousId;
492
+ } catch {
493
+ return false;
494
+ }
495
+ }
496
+ function showFirstRunNotice() {
497
+ process.stderr.write(
498
+ "\nCanonry collects anonymous telemetry to prioritize features.\nDisable any time: canonry telemetry disable\nLearn more: https://canonry.ai/telemetry\n\n"
499
+ );
500
+ }
501
+ function detectAndTrackUpgrade() {
502
+ if (!isTelemetryEnabled()) return;
503
+ if (!configExists()) return;
504
+ let lastSeen;
505
+ try {
506
+ const raw = loadConfigRaw();
507
+ lastSeen = raw?.lastSeenVersion;
508
+ } catch {
509
+ return;
510
+ }
511
+ if (lastSeen === VERSION) return;
512
+ try {
513
+ saveConfigPatch({ lastSeenVersion: VERSION });
514
+ } catch {
515
+ return;
516
+ }
517
+ if (!lastSeen) return;
518
+ trackEvent("cli.upgraded", { fromVersion: lastSeen, toVersion: VERSION });
519
+ }
520
+ function trackEvent(event, properties, options) {
521
+ void deliverEvent(event, properties, options);
522
+ }
523
+ function recordDashboardEvent(event) {
524
+ const { event: eventName, eventId, ...properties } = event;
525
+ trackEvent(eventName, properties, { source: "dashboard", eventId: String(eventId) });
526
+ }
527
+ function setTelemetryPreference(enabled, method, attribution) {
528
+ loadConfig();
529
+ const announce = !enabled && isTelemetryEnabled();
530
+ saveConfigPatch({ telemetry: enabled });
531
+ const who = attribution ?? (method === "cli" ? { surface: "cli", agent: cliRuntimeContext().agent } : { surface: "system" });
532
+ const properties = {
533
+ method,
534
+ surface: who.surface,
535
+ ...who.agent ? { agent: who.agent } : {}
536
+ };
537
+ return announce ? deliverEvent("telemetry.disabled", properties, void 0, { preferenceChecked: true }) : Promise.resolve();
538
+ }
539
+ function environmentField() {
540
+ try {
541
+ const flags = telemetryEnvironment();
542
+ return flags.length > 0 ? { environment: flags } : {};
543
+ } catch {
544
+ return {};
545
+ }
546
+ }
547
+ function deliverEvent(event, properties, options, delivery = {}) {
548
+ if (!delivery.preferenceChecked && !isTelemetryEnabled()) return Promise.resolve();
549
+ if (isGhostTelemetryEvent(event, properties)) return Promise.resolve();
550
+ const anonymousId = getOrCreateAnonymousId();
551
+ if (!anonymousId) return Promise.resolve();
552
+ const machine = getMachineId();
553
+ const payload = {
554
+ eventId: options?.eventId ?? crypto.randomUUID(),
555
+ anonymousId,
556
+ ...machine ? { machineId: machine } : {},
557
+ sessionId: SESSION_ID,
558
+ source: options?.source ?? envSourceOverride() ?? CURRENT_SOURCE,
559
+ event,
560
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
561
+ version: VERSION,
562
+ nodeVersion: process.versions.node,
563
+ os: process.platform,
564
+ arch: process.arch,
565
+ ...options?.sourceContext ? { sourceContext: options.sourceContext } : {},
566
+ ...options?.errorCode ? { errorCode: options.errorCode } : {},
567
+ ...environmentField(),
568
+ ...properties ? { properties } : {}
569
+ };
570
+ const controller = new AbortController();
571
+ const timeout = setTimeout(() => controller.abort(), TIMEOUT_MS);
572
+ timeout.unref();
573
+ try {
574
+ return fetch(TELEMETRY_ENDPOINT, {
575
+ method: "POST",
576
+ headers: { "Content-Type": "application/json" },
577
+ body: JSON.stringify(payload),
578
+ signal: controller.signal
579
+ }).then(() => void 0, () => void 0).finally(() => clearTimeout(timeout));
580
+ } catch {
581
+ clearTimeout(timeout);
582
+ return Promise.resolve();
583
+ }
584
+ }
585
+
586
+ export {
587
+ cliRuntimeContext,
588
+ checkLatestVersionForCli,
589
+ readCachedUpdateAvailable,
590
+ notePrintedUpdateAvailable,
591
+ getPrintedUpdateAvailable,
592
+ formatUpdateNotice,
593
+ checkLatestVersionForServer,
594
+ getServerUpdateStatus,
595
+ recordInstallRef,
596
+ installAttribution,
597
+ bucketCliCommandDuration,
598
+ trackCliCommandFinished,
599
+ setTelemetrySource,
600
+ getTelemetryStatus,
601
+ isTelemetryEnabled,
602
+ getOrCreateAnonymousId,
603
+ isFirstRun,
604
+ showFirstRunNotice,
605
+ detectAndTrackUpgrade,
606
+ trackEvent,
607
+ recordDashboardEvent,
608
+ setTelemetryPreference
609
+ };
@@ -0,0 +1,18 @@
1
+ // src/serve-endpoint.ts
2
+ function resolveServePort(envPort, configPort) {
3
+ const trimmed = envPort?.trim();
4
+ if (trimmed) return parseInt(trimmed, 10);
5
+ return configPort ?? 4100;
6
+ }
7
+ function isLoopbackBindHost(host) {
8
+ if (host == null || host === "") return true;
9
+ const normalized = host.trim().toLowerCase().replace(/^\[|\]$/g, "");
10
+ if (normalized === "localhost" || normalized === "::1") return true;
11
+ if (/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(normalized)) return true;
12
+ return false;
13
+ }
14
+
15
+ export {
16
+ resolveServePort,
17
+ isLoopbackBindHost
18
+ };
@@ -1,17 +1,19 @@
1
1
  import {
2
- BUNDLED_SKILL_NAMES,
3
2
  configExists,
4
- installSkills,
5
3
  loadConfigRaw,
6
4
  saveConfigPatch
7
- } from "./chunk-HAHXPJQ5.js";
5
+ } from "./chunk-UQ3MOZGC.js";
6
+ import {
7
+ BUNDLED_SKILL_NAMES,
8
+ installSkills
9
+ } from "./chunk-B2FR2ZQ4.js";
8
10
  import {
9
11
  PACKAGE_VERSION
10
- } from "./chunk-KEATAHXH.js";
12
+ } from "./chunk-AOJU5LKX.js";
11
13
  import {
12
14
  SKILL_MANIFEST_FILENAME,
13
15
  SkillsClients
14
- } from "./chunk-SFMWHPMX.js";
16
+ } from "./chunk-D6COIM3U.js";
15
17
 
16
18
  // src/skills-autosync.ts
17
19
  import fs from "fs";