@canonry/canonry 7.51.5 → 7.52.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/assets/agent-workspace/skills/canonry/references/canonry-cli.md +8 -0
- package/assets/assets/{AccessControls-B5TqDgeq.js → AccessControls-CteIuEGI.js} +1 -1
- package/assets/assets/{AuditHistoryPanel-DgxiizOW.js → AuditHistoryPanel-DqJGiLsf.js} +1 -1
- package/assets/assets/{BacklinksPage-Ay6pdphx.js → BacklinksPage-DotWEPQt.js} +1 -1
- package/assets/assets/{HistoryPage-B11eFH21.js → HistoryPage-aOd198dT.js} +1 -1
- package/assets/assets/MeasurementPropertyPage-CuaKVK8x.js +4 -0
- package/assets/assets/{ProjectPage-DoY0hftd.js → ProjectPage-O9oufMgi.js} +4 -4
- package/assets/assets/{RunsPage-BPBmuQAS.js → RunsPage-DIXMrc-N.js} +1 -1
- package/assets/assets/{SettingsPage-ClKnP8xy.js → SettingsPage-BuGb6AGa.js} +1 -1
- package/assets/assets/SiteHealthSection-CweaKjCo.js +2 -0
- package/assets/assets/TrafficPage-B7MaQalp.js +40 -0
- package/assets/assets/{TrafficSourceDetailPage-DQu0YNt2.js → TrafficSourceDetailPage-BPtjnF9s.js} +1 -1
- package/assets/assets/{card-DYMyvhB9.js → card-DoV-8Txo.js} +1 -1
- package/assets/assets/{extract-error-message-BRM1I_3L.js → extract-error-message-DKQJJlZ-.js} +1 -1
- package/assets/assets/{format-helpers-DrkFERj3.js → format-helpers-BWnMmkiO.js} +1 -1
- package/assets/assets/index-Z63c4PeO.js +39 -0
- package/assets/assets/{query-client-gRFnU4VF.js → query-client-vB35tVTz.js} +1 -1
- package/assets/assets/{react-query-lH82FULK.js → react-query-BI0567qs.js} +1 -1
- package/assets/assets/{react-sigma_core.esm.min-D09H4byP.js → react-sigma_core.esm.min-hGyOC4V_.js} +1 -1
- package/assets/assets/{service-Cx0HSnE9.js → service-c4YvpVKX.js} +1 -1
- package/assets/index.html +6 -6
- package/dist/ads-MREK2AGL.js +544 -0
- package/dist/agent-4RUZ3MC4.js +70 -0
- package/dist/agent-ask-YLTYBEYH.js +139 -0
- package/dist/agent-conversations-QA6IKDGR.js +52 -0
- package/dist/agent-memory-MEQAJOB3.js +92 -0
- package/dist/agent-providers-AXYPDJHL.js +55 -0
- package/dist/agent-transcript-SMNQNYCD.js +77 -0
- package/dist/analytics-4OR64IGV.js +240 -0
- package/dist/apply-CQXCFXAH.js +175 -0
- package/dist/backfill-TMXCNVOB.js +41 -0
- package/dist/backlinks-6KFAQGYV.js +303 -0
- package/dist/bing-HFCACTAC.js +418 -0
- package/dist/bootstrap-SQVQXOJC.js +326 -0
- package/dist/cdp-IACL7EXU.js +162 -0
- package/dist/chunk-4MJYGB56.js +124 -0
- package/dist/chunk-5N6245R7.js +1160 -0
- package/dist/chunk-6BPZHNDC.js +617 -0
- package/dist/chunk-6GO5VVAC.js +15 -0
- package/dist/chunk-7244X3K6.js +609 -0
- package/dist/chunk-7XE2IRBG.js +204 -0
- package/dist/chunk-AOJU5LKX.js +8 -0
- package/dist/chunk-AWCWIQAU.js +2686 -0
- package/dist/{chunk-JBZZEIM2.js → chunk-BBOHY2DQ.js} +2 -13
- package/dist/{chunk-AZFPA7JV.js → chunk-BU3VAG5J.js} +6 -4
- package/dist/{chunk-4YCGZGA3.js → chunk-BYOK6Z4F.js} +2 -2
- package/dist/chunk-DSNSD5J3.js +971 -0
- package/dist/chunk-EGIZNSDA.js +94 -0
- package/dist/chunk-ELCLGWUT.js +83 -0
- package/dist/chunk-FC4XND45.js +38 -0
- package/dist/chunk-GNKOBKPW.js +58 -0
- package/dist/chunk-HEGXGCGL.js +524 -0
- package/dist/chunk-I6KNMZ77.js +232 -0
- package/dist/{chunk-HLVEB5TB.js → chunk-IIOEAJTV.js} +7 -5
- package/dist/chunk-ILDT4LPB.js +1273 -0
- package/dist/chunk-JY3RLZGB.js +30 -0
- package/dist/{chunk-PLYJX67A.js → chunk-K5I45PZI.js} +8084 -13939
- package/dist/chunk-KXAOMTXN.js +1034 -0
- package/dist/chunk-LK2BG6EX.js +145 -0
- package/dist/chunk-MJNUSPO4.js +15 -0
- package/dist/chunk-MKAC7HKH.js +9178 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/{chunk-SFMWHPMX.js → chunk-O4RMPA6H.js} +13765 -13737
- package/dist/chunk-O77IBNVO.js +8264 -0
- package/dist/chunk-OFL4PTYU.js +644 -0
- package/dist/chunk-QLPLENDT.js +133 -0
- package/dist/chunk-R2J4SNKF.js +78 -0
- package/dist/{chunk-KEATAHXH.js → chunk-RVUCY4ZV.js} +358 -581
- package/dist/chunk-SNFBJKAW.js +530 -0
- package/dist/chunk-TALC5DX5.js +420 -0
- package/dist/chunk-TSENU4GG.js +18 -0
- package/dist/{chunk-HAHXPJQ5.js → chunk-V5D4XNWV.js} +16 -1684
- package/dist/chunk-VJWDBFSL.js +69 -0
- package/dist/chunk-XEBKF4N5.js +8 -0
- package/dist/chunk-Y4GK7GCV.js +15376 -0
- package/dist/{chunk-A3WSAAQS.js → chunk-YSEC6TIB.js} +7917 -33199
- package/dist/chunk-Z7IUAJOF.js +13 -0
- package/dist/citations-NSBBWRZ4.js +106 -0
- package/dist/{cli-catalog-MO6Z2CIZ.js → cli-catalog-OFWJMNMD.js} +5 -3
- package/dist/cli-commands-WVBL337U.js +19 -0
- package/dist/cli.js +35 -29
- package/dist/competitor-V4OHORBC.js +561 -0
- package/dist/content-RUXRI5IC.js +257 -0
- package/dist/dashboard-JXB2YAQJ.js +71 -0
- package/dist/demo-55ZNUOXU.js +75 -0
- package/dist/{demo-server-GIWDJGJX.js → demo-server-XO7PHM4I.js} +22 -9
- package/dist/discover-JJQ564HS.js +372 -0
- package/dist/discover-eval-KLEKZ6U4.js +282 -0
- package/dist/doctor-JAMQZCMZ.js +152 -0
- package/dist/evidence-YRSB7GFE.js +57 -0
- package/dist/export-cmd-MHML4OYU.js +49 -0
- package/dist/ga-LSXPE2MN.js +911 -0
- package/dist/gbp-RMKMLOC7.js +370 -0
- package/dist/google-JQ4T6JTQ.js +946 -0
- package/dist/google-marketing-J6SEODYC.js +403 -0
- package/dist/health-cmd-MV2JM2C3.js +64 -0
- package/dist/history-SRRH7A2E.js +90 -0
- package/dist/index.d.ts +43 -4
- package/dist/index.js +29 -6
- package/dist/init-ZJZFUERV.js +432 -0
- package/dist/insights-PMMGNWZH.js +63 -0
- package/dist/intelligence-service-KCSU6ZUJ.js +15 -0
- package/dist/keys-TS7NZANS.js +116 -0
- package/dist/keyword-VNCKDUGC.js +164 -0
- package/dist/logs-VH3WOTZJ.js +30 -0
- package/dist/mcp-DG2RROB3.js +14 -0
- package/dist/mcp.js +14 -5
- package/dist/measurement-plan-4T35TUGG.js +42 -0
- package/dist/notify-BWHUSKL7.js +125 -0
- package/dist/organic-evidence-QX4SXXJP.js +53 -0
- package/dist/overview-7IHUTKUV.js +213 -0
- package/dist/project-JXLSWDE2.js +460 -0
- package/dist/query-S75EL25H.js +211 -0
- package/dist/research-KFTV3IP4.js +200 -0
- package/dist/results-export-GTKVBU34.js +27 -0
- package/dist/run-26HDIRHF.js +31 -0
- package/dist/schedule-N6G4SVHQ.js +177 -0
- package/dist/search-MI32EPYM.js +42 -0
- package/dist/serve-XLGE42AG.js +598 -0
- package/dist/session-W5DXWIYM.js +47 -0
- package/dist/settings-T7WI2UVE.js +107 -0
- package/dist/skills-F3WPKPTK.js +33 -0
- package/dist/snapshot-PD3EAVEX.js +538 -0
- package/dist/src-XDUXMJC3.js +316 -0
- package/dist/status-PUH7JFZ4.js +126 -0
- package/dist/support-ARF4HER7.js +24 -0
- package/dist/technical-aeo-AUFWWJIP.js +625 -0
- package/dist/telemetry-XBYT7G2K.js +118 -0
- package/dist/tools-GVHIRWSN.js +41 -0
- package/dist/traffic-B3HW2ZWG.js +1295 -0
- package/dist/users-M5HNQZYI.js +170 -0
- package/dist/visibility-stats-Y7GJKMHN.js +241 -0
- package/dist/wordpress-GCIURYPN.js +600 -0
- package/package.json +1 -1
- package/assets/assets/MeasurementPropertyPage-1UYI7mzP.js +0 -4
- package/assets/assets/SiteHealthSection-PWjKMmEn.js +0 -2
- package/assets/assets/TrafficPage-DkfGiJXR.js +0 -40
- package/assets/assets/index-CG1Jox52.js +0 -39
- package/dist/chunk-4QQYYRHV.js +0 -23082
- package/dist/cli-commands-FOJR3HHU.js +0 -15
- package/dist/intelligence-service-XQCNWAPL.js +0 -9
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import {
|
|
2
|
+
trackCliConnection
|
|
3
|
+
} from "./chunk-MJNUSPO4.js";
|
|
4
|
+
import {
|
|
5
|
+
outcomeFailure
|
|
6
|
+
} from "./chunk-I6KNMZ77.js";
|
|
7
|
+
import {
|
|
8
|
+
isLoopbackBindHost
|
|
9
|
+
} from "./chunk-TSENU4GG.js";
|
|
10
|
+
import {
|
|
11
|
+
registeredProviderNames
|
|
12
|
+
} from "./chunk-JY3RLZGB.js";
|
|
13
|
+
import {
|
|
14
|
+
isTelemetryEnabled,
|
|
15
|
+
recordInstallRef
|
|
16
|
+
} from "./chunk-7244X3K6.js";
|
|
17
|
+
import {
|
|
18
|
+
createApiClient
|
|
19
|
+
} from "./chunk-V5D4XNWV.js";
|
|
20
|
+
import {
|
|
21
|
+
configExists,
|
|
22
|
+
getBootstrapEnv,
|
|
23
|
+
getConfigDir,
|
|
24
|
+
getConfigPath,
|
|
25
|
+
loadConfig,
|
|
26
|
+
loadConfigRaw,
|
|
27
|
+
saveConfig,
|
|
28
|
+
withBootstrapProviderDefaults
|
|
29
|
+
} from "./chunk-OFL4PTYU.js";
|
|
30
|
+
import "./chunk-AOJU5LKX.js";
|
|
31
|
+
import {
|
|
32
|
+
CliError,
|
|
33
|
+
isEndpointMissing,
|
|
34
|
+
isMachineFormat,
|
|
35
|
+
systemError
|
|
36
|
+
} from "./chunk-HGMYEDAQ.js";
|
|
37
|
+
import "./chunk-QLPLENDT.js";
|
|
38
|
+
import {
|
|
39
|
+
apiKeys,
|
|
40
|
+
createClient,
|
|
41
|
+
dashboardSessions,
|
|
42
|
+
migrate
|
|
43
|
+
} from "./chunk-MKAC7HKH.js";
|
|
44
|
+
import {
|
|
45
|
+
ProviderNames,
|
|
46
|
+
ProviderReloadErrorReasons
|
|
47
|
+
} from "./chunk-O4RMPA6H.js";
|
|
48
|
+
import "./chunk-MLKGABMK.js";
|
|
49
|
+
|
|
50
|
+
// src/commands/bootstrap.ts
|
|
51
|
+
import crypto from "crypto";
|
|
52
|
+
import path from "path";
|
|
53
|
+
import { isDeepStrictEqual } from "util";
|
|
54
|
+
import { eq } from "drizzle-orm";
|
|
55
|
+
function persistedValue(value) {
|
|
56
|
+
if (Array.isArray(value)) return value.map(persistedValue);
|
|
57
|
+
if (value && typeof value === "object") {
|
|
58
|
+
return Object.fromEntries(
|
|
59
|
+
Object.entries(value).filter(([, entry]) => entry !== void 0).map(([key, entry]) => [key, persistedValue(entry)])
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
var PROVIDER_FREE_NEXT_STEPS = [
|
|
65
|
+
"AI Visibility needs an answer-engine provider. Page Health does not.",
|
|
66
|
+
"With the server running, the operator runs `canonry settings provider gemini --api-key <key>` (free key at https://aistudio.google.com/apikey). It takes effect immediately.",
|
|
67
|
+
"Or the operator sets GEMINI_API_KEY and reruns `canonry bootstrap`. It reloads the matching running local server and confirms active providers; an offline server uses the saved settings at startup.",
|
|
68
|
+
"A provider key is the operator's credential: never ask for it in chat."
|
|
69
|
+
];
|
|
70
|
+
var PROVIDER_CREDENTIAL_FIELDS = {
|
|
71
|
+
[ProviderNames.gemini]: ["apiKey", "vertexProject", "vertexRegion", "vertexCredentials"],
|
|
72
|
+
// A local key belongs to the server at its base URL.
|
|
73
|
+
[ProviderNames.local]: ["baseUrl", "apiKey"]
|
|
74
|
+
};
|
|
75
|
+
var API_KEY_CREDENTIAL_FIELDS = ["apiKey"];
|
|
76
|
+
function mergeEnvProvider(name, saved, fromEnv) {
|
|
77
|
+
const credentialFields = PROVIDER_CREDENTIAL_FIELDS[name] ?? API_KEY_CREDENTIAL_FIELDS;
|
|
78
|
+
const envFields = Object.entries(fromEnv);
|
|
79
|
+
const envValues = new Map(envFields);
|
|
80
|
+
const merged = {};
|
|
81
|
+
for (const [field, value] of Object.entries(saved ?? {})) {
|
|
82
|
+
if (envValues.get(field) !== void 0) merged[field] = envValues.get(field);
|
|
83
|
+
else if (!credentialFields.includes(field)) merged[field] = value;
|
|
84
|
+
}
|
|
85
|
+
for (const [field, value] of envFields) {
|
|
86
|
+
if (!(field in merged)) merged[field] = value;
|
|
87
|
+
}
|
|
88
|
+
return withBootstrapProviderDefaults(name, merged);
|
|
89
|
+
}
|
|
90
|
+
var ServerReloadStatuses = {
|
|
91
|
+
reloaded: "reloaded",
|
|
92
|
+
unchanged: "unchanged",
|
|
93
|
+
unavailable: "unavailable",
|
|
94
|
+
"not-local": "not-local",
|
|
95
|
+
"not-matching": "not-matching",
|
|
96
|
+
failed: "failed"
|
|
97
|
+
};
|
|
98
|
+
var NotMatchingReasons = {
|
|
99
|
+
"other-install": "other-install",
|
|
100
|
+
"reload-unsupported": "reload-unsupported"
|
|
101
|
+
};
|
|
102
|
+
function notMatchingReason(err) {
|
|
103
|
+
const status = err.details?.httpStatus;
|
|
104
|
+
if (status === 401 || status === 403) return NotMatchingReasons["other-install"];
|
|
105
|
+
if (err.details?.reason === ProviderReloadErrorReasons["install-identity-mismatch"]) return NotMatchingReasons["other-install"];
|
|
106
|
+
if (isEndpointMissing(err) || status === 501) return NotMatchingReasons["reload-unsupported"];
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
function notMatchingLines(reason, serverUrl) {
|
|
110
|
+
switch (reason) {
|
|
111
|
+
case NotMatchingReasons["other-install"]:
|
|
112
|
+
return [
|
|
113
|
+
`The server at ${serverUrl} is not this install's server, so it was not reloaded.`,
|
|
114
|
+
"To apply the saved providers, run `canonry settings reload-providers` against this install's server, or restart that server."
|
|
115
|
+
];
|
|
116
|
+
case NotMatchingReasons["reload-unsupported"]:
|
|
117
|
+
return [
|
|
118
|
+
`The server at ${serverUrl} cannot reload providers: it is too old or does not support reload.`,
|
|
119
|
+
"Restart this install's server to apply the saved providers."
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function bootstrapCommand(opts) {
|
|
124
|
+
const format = opts?.format ?? "text";
|
|
125
|
+
const configDir = getConfigDir();
|
|
126
|
+
const existing = configExists();
|
|
127
|
+
const existingConfig = existing ? loadConfig() : void 0;
|
|
128
|
+
const existingRaw = existing ? loadConfigRaw() : null;
|
|
129
|
+
const env = getBootstrapEnv(process.env);
|
|
130
|
+
const databasePath = env.databasePath || existingRaw?.database || path.join(configDir, "data.db");
|
|
131
|
+
let rawApiKey;
|
|
132
|
+
let generatedApiKey;
|
|
133
|
+
if (env.apiKey) {
|
|
134
|
+
rawApiKey = env.apiKey;
|
|
135
|
+
} else if (existingRaw) {
|
|
136
|
+
rawApiKey = existingRaw.apiKey;
|
|
137
|
+
} else {
|
|
138
|
+
generatedApiKey = `cnry_${crypto.randomBytes(16).toString("hex")}`;
|
|
139
|
+
rawApiKey = generatedApiKey;
|
|
140
|
+
}
|
|
141
|
+
const mergedProviders = { ...existingConfig?.providers };
|
|
142
|
+
for (const [name, fromEnv] of Object.entries(env.providers)) {
|
|
143
|
+
if (fromEnv) mergedProviders[name] = mergeEnvProvider(name, mergedProviders[name], fromEnv);
|
|
144
|
+
}
|
|
145
|
+
if (env.googleClientId && !env.googleClientSecret || !env.googleClientId && env.googleClientSecret) {
|
|
146
|
+
console.warn("Warning: GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET must both be set to configure Google OAuth. Skipping Google auth config.");
|
|
147
|
+
}
|
|
148
|
+
const mergedGoogle = env.googleClientId && env.googleClientSecret ? {
|
|
149
|
+
clientId: env.googleClientId,
|
|
150
|
+
clientSecret: env.googleClientSecret,
|
|
151
|
+
connections: existingConfig?.google?.connections ?? []
|
|
152
|
+
} : existingConfig?.google;
|
|
153
|
+
const keyHash = crypto.createHash("sha256").update(rawApiKey).digest("hex");
|
|
154
|
+
const keyPrefix = rawApiKey.slice(0, 9);
|
|
155
|
+
const existingConfigKeyHash = existingRaw ? crypto.createHash("sha256").update(existingRaw.apiKey).digest("hex") : void 0;
|
|
156
|
+
const db = createClient(databasePath);
|
|
157
|
+
migrate(db);
|
|
158
|
+
const keyChanged = db.transaction((tx) => {
|
|
159
|
+
let changed = false;
|
|
160
|
+
const rotatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
161
|
+
const existingDefaults = tx.select({
|
|
162
|
+
id: apiKeys.id,
|
|
163
|
+
keyHash: apiKeys.keyHash,
|
|
164
|
+
keyPrefix: apiKeys.keyPrefix,
|
|
165
|
+
scopes: apiKeys.scopes,
|
|
166
|
+
projectId: apiKeys.projectId,
|
|
167
|
+
lastUsedAt: apiKeys.lastUsedAt,
|
|
168
|
+
revokedAt: apiKeys.revokedAt
|
|
169
|
+
}).from(apiKeys).where(eq(apiKeys.name, "default")).all();
|
|
170
|
+
const existingDefault = existingDefaults.find((key) => key.keyHash === existingConfigKeyHash) ?? existingDefaults.at(0);
|
|
171
|
+
if (existingDefault) {
|
|
172
|
+
const rotating = existingDefault.keyHash !== keyHash;
|
|
173
|
+
const needsUpdate = rotating || existingDefault.keyPrefix !== keyPrefix || !isDeepStrictEqual(existingDefault.scopes, ["*"]) || existingDefault.projectId !== null || existingDefault.revokedAt !== null;
|
|
174
|
+
if (needsUpdate) {
|
|
175
|
+
if (rotating || existingDefault.revokedAt !== null) {
|
|
176
|
+
tx.delete(dashboardSessions).where(eq(dashboardSessions.apiKeyId, existingDefault.id)).run();
|
|
177
|
+
}
|
|
178
|
+
tx.update(apiKeys).set({
|
|
179
|
+
keyHash,
|
|
180
|
+
keyPrefix,
|
|
181
|
+
scopes: ["*"],
|
|
182
|
+
projectId: null,
|
|
183
|
+
...rotating ? { lastUsedAt: null } : {},
|
|
184
|
+
revokedAt: null
|
|
185
|
+
}).where(eq(apiKeys.id, existingDefault.id)).run();
|
|
186
|
+
changed = true;
|
|
187
|
+
}
|
|
188
|
+
for (const duplicate of existingDefaults) {
|
|
189
|
+
if (duplicate.id === existingDefault.id) continue;
|
|
190
|
+
tx.delete(dashboardSessions).where(eq(dashboardSessions.apiKeyId, duplicate.id)).run();
|
|
191
|
+
if (duplicate.revokedAt === null) {
|
|
192
|
+
tx.update(apiKeys).set({ revokedAt: rotatedAt }).where(eq(apiKeys.id, duplicate.id)).run();
|
|
193
|
+
changed = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
tx.insert(apiKeys).values({
|
|
198
|
+
id: crypto.randomUUID(),
|
|
199
|
+
name: "default",
|
|
200
|
+
keyHash,
|
|
201
|
+
keyPrefix,
|
|
202
|
+
scopes: ["*"],
|
|
203
|
+
createdAt: rotatedAt
|
|
204
|
+
}).run();
|
|
205
|
+
changed = true;
|
|
206
|
+
}
|
|
207
|
+
return changed;
|
|
208
|
+
});
|
|
209
|
+
const apiUrl = env.apiUrl || existingRaw?.apiUrl || `http://127.0.0.1:${process.env.CANONRY_PORT || "4100"}`;
|
|
210
|
+
const nextConfig = {
|
|
211
|
+
...existingRaw,
|
|
212
|
+
apiUrl,
|
|
213
|
+
database: databasePath,
|
|
214
|
+
apiKey: rawApiKey,
|
|
215
|
+
providers: mergedProviders,
|
|
216
|
+
google: mergedGoogle
|
|
217
|
+
};
|
|
218
|
+
const providersChanged = !isDeepStrictEqual(persistedValue(existingRaw?.providers ?? {}), persistedValue(mergedProviders));
|
|
219
|
+
const configChanged = !existingRaw || existingRaw.apiUrl !== apiUrl || existingRaw.database !== databasePath || existingRaw.apiKey !== rawApiKey || providersChanged || !isDeepStrictEqual(persistedValue(existingRaw.google), persistedValue(mergedGoogle));
|
|
220
|
+
const providerConnections = Object.keys(env.providers).filter((name) => env.providers[name] && !isDeepStrictEqual(persistedValue(existingRaw?.providers?.[name]), persistedValue(mergedProviders[name]))).map((name) => ({ integration: "provider", provider: name, action: existingRaw?.providers?.[name] ? "reauth" : "connect" }));
|
|
221
|
+
if (configChanged) {
|
|
222
|
+
try {
|
|
223
|
+
saveConfig(nextConfig);
|
|
224
|
+
} catch (err) {
|
|
225
|
+
for (const connection of providerConnections) trackCliConnection({ ...connection, status: "failed", ...outcomeFailure(err) });
|
|
226
|
+
throw err;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (isTelemetryEnabled()) recordInstallRef(opts?.ref);
|
|
230
|
+
for (const connection of providerConnections) trackCliConnection({ ...connection, status: "succeeded" });
|
|
231
|
+
const status = !existing ? "created" : configChanged || keyChanged ? "updated" : "unchanged";
|
|
232
|
+
const providerFree = registeredProviderNames(nextConfig).length === 0;
|
|
233
|
+
const serverUrl = loadConfig().apiUrl;
|
|
234
|
+
let serverReload;
|
|
235
|
+
let reloadFailure;
|
|
236
|
+
if (!isLoopbackBindHost(new URL(serverUrl).hostname)) {
|
|
237
|
+
serverReload = { status: ServerReloadStatuses["not-local"] };
|
|
238
|
+
} else if (!providersChanged) {
|
|
239
|
+
serverReload = { status: ServerReloadStatuses.unchanged };
|
|
240
|
+
} else {
|
|
241
|
+
const signal = AbortSignal.timeout(4e3);
|
|
242
|
+
try {
|
|
243
|
+
const receipt = await createApiClient().reloadProviders({ configPath: getConfigPath(), databasePath }, signal);
|
|
244
|
+
serverReload = {
|
|
245
|
+
status: ServerReloadStatuses.reloaded,
|
|
246
|
+
providers: receipt.providers.filter((provider) => provider.configured).map((provider) => provider.name)
|
|
247
|
+
};
|
|
248
|
+
} catch (err) {
|
|
249
|
+
const reason = err instanceof CliError ? notMatchingReason(err) : void 0;
|
|
250
|
+
if (err instanceof CliError && err.code === "CONNECTION_ERROR" && err.details?.connectionUnavailable === true && !signal.aborted) {
|
|
251
|
+
serverReload = { status: ServerReloadStatuses.unavailable };
|
|
252
|
+
} else if (err instanceof CliError && reason) {
|
|
253
|
+
serverReload = { status: ServerReloadStatuses["not-matching"], reason, code: err.code };
|
|
254
|
+
} else {
|
|
255
|
+
reloadFailure = err instanceof CliError ? err : systemError("Provider configuration was saved, but server reload failed.");
|
|
256
|
+
serverReload = { status: ServerReloadStatuses.failed, code: reloadFailure.code };
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const reloadSteps = (() => {
|
|
261
|
+
switch (serverReload.status) {
|
|
262
|
+
case ServerReloadStatuses.unavailable:
|
|
263
|
+
return ["Start `canonry serve` to use the saved configuration."];
|
|
264
|
+
case ServerReloadStatuses.failed:
|
|
265
|
+
return ["Resolve the server reload error, then run `canonry settings reload-providers`."];
|
|
266
|
+
case ServerReloadStatuses["not-matching"]:
|
|
267
|
+
return [notMatchingLines(serverReload.reason, serverUrl).join(" ")];
|
|
268
|
+
case ServerReloadStatuses.reloaded:
|
|
269
|
+
case ServerReloadStatuses.unchanged:
|
|
270
|
+
case ServerReloadStatuses["not-local"]:
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
})();
|
|
274
|
+
const nextSteps = [...providerFree ? PROVIDER_FREE_NEXT_STEPS : [], ...reloadSteps];
|
|
275
|
+
if (isMachineFormat(format)) {
|
|
276
|
+
console.log(JSON.stringify({
|
|
277
|
+
bootstrapped: true,
|
|
278
|
+
status,
|
|
279
|
+
changed: status !== "unchanged",
|
|
280
|
+
configPath: getConfigPath(),
|
|
281
|
+
databasePath,
|
|
282
|
+
apiUrl,
|
|
283
|
+
providers: Object.keys(mergedProviders),
|
|
284
|
+
googleConfigured: !!mergedGoogle,
|
|
285
|
+
generatedApiKey,
|
|
286
|
+
serverReload,
|
|
287
|
+
nextSteps
|
|
288
|
+
}, null, 2));
|
|
289
|
+
if (reloadFailure) throw reloadFailure;
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
console.log(`Bootstrap ${status}. Config: ${getConfigPath()}`);
|
|
293
|
+
console.log(`SQLite database path: ${databasePath}`);
|
|
294
|
+
switch (serverReload.status) {
|
|
295
|
+
case ServerReloadStatuses.reloaded:
|
|
296
|
+
console.log(`Providers active on the running server: ${serverReload.providers.join(", ") || "none"}.`);
|
|
297
|
+
break;
|
|
298
|
+
case ServerReloadStatuses.unavailable:
|
|
299
|
+
console.log("Start `canonry serve` to use the saved configuration.");
|
|
300
|
+
break;
|
|
301
|
+
case ServerReloadStatuses["not-local"]:
|
|
302
|
+
console.log("Configuration saved locally. The configured remote server was not reloaded.");
|
|
303
|
+
break;
|
|
304
|
+
case ServerReloadStatuses["not-matching"]:
|
|
305
|
+
for (const line of notMatchingLines(serverReload.reason, serverUrl)) console.log(line);
|
|
306
|
+
break;
|
|
307
|
+
case ServerReloadStatuses.unchanged:
|
|
308
|
+
if (existing) console.log("Provider settings unchanged, so the server was not reloaded.");
|
|
309
|
+
break;
|
|
310
|
+
case ServerReloadStatuses.failed:
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
if (providerFree) {
|
|
314
|
+
console.log("Providers: none (Page Health works now; add one later to enable AI Visibility).");
|
|
315
|
+
console.log(" To add one with the server running: canonry settings provider gemini --api-key <key>");
|
|
316
|
+
console.log(" (free key at aistudio.google.com). Or set GEMINI_API_KEY and rerun `canonry bootstrap`;");
|
|
317
|
+
console.log(" bootstrap reloads the matching running local server and confirms active providers.");
|
|
318
|
+
}
|
|
319
|
+
if (generatedApiKey) {
|
|
320
|
+
console.log(`API key (for the CLI, MCP, and agents): ${generatedApiKey}`);
|
|
321
|
+
}
|
|
322
|
+
if (reloadFailure) throw reloadFailure;
|
|
323
|
+
}
|
|
324
|
+
export {
|
|
325
|
+
bootstrapCommand
|
|
326
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import {
|
|
2
|
+
trackCliConnection
|
|
3
|
+
} from "./chunk-MJNUSPO4.js";
|
|
4
|
+
import {
|
|
5
|
+
outcomeFailure
|
|
6
|
+
} from "./chunk-I6KNMZ77.js";
|
|
7
|
+
import "./chunk-7244X3K6.js";
|
|
8
|
+
import {
|
|
9
|
+
createApiClient
|
|
10
|
+
} from "./chunk-V5D4XNWV.js";
|
|
11
|
+
import {
|
|
12
|
+
loadConfig,
|
|
13
|
+
saveConfigPatch
|
|
14
|
+
} from "./chunk-OFL4PTYU.js";
|
|
15
|
+
import "./chunk-AOJU5LKX.js";
|
|
16
|
+
import {
|
|
17
|
+
CliError,
|
|
18
|
+
isMachineFormat
|
|
19
|
+
} from "./chunk-HGMYEDAQ.js";
|
|
20
|
+
import "./chunk-QLPLENDT.js";
|
|
21
|
+
import {
|
|
22
|
+
describeError
|
|
23
|
+
} from "./chunk-O4RMPA6H.js";
|
|
24
|
+
import "./chunk-MLKGABMK.js";
|
|
25
|
+
|
|
26
|
+
// src/commands/cdp.ts
|
|
27
|
+
function getClient() {
|
|
28
|
+
return createApiClient();
|
|
29
|
+
}
|
|
30
|
+
async function cdpConnect(opts) {
|
|
31
|
+
const config = loadConfig();
|
|
32
|
+
const host = opts.host ?? "localhost";
|
|
33
|
+
const port = parseInt(opts.port ?? "9222", 10);
|
|
34
|
+
config.cdp = {
|
|
35
|
+
...config.cdp,
|
|
36
|
+
host,
|
|
37
|
+
port
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
saveConfigPatch(config);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
trackCliConnection({ integration: "cdp", action: "connect", status: "failed", ...outcomeFailure(err) });
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
trackCliConnection({ integration: "cdp", action: "connect", status: "succeeded" });
|
|
46
|
+
if (isMachineFormat(opts.format)) {
|
|
47
|
+
console.log(JSON.stringify({
|
|
48
|
+
host,
|
|
49
|
+
port,
|
|
50
|
+
endpoint: `ws://${host}:${port}`,
|
|
51
|
+
restartRequired: true
|
|
52
|
+
}, null, 2));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
console.log(`CDP endpoint configured: ws://${host}:${port}`);
|
|
56
|
+
console.log("Restart canonry server for changes to take effect.");
|
|
57
|
+
}
|
|
58
|
+
async function cdpStatus(format) {
|
|
59
|
+
const client = getClient();
|
|
60
|
+
try {
|
|
61
|
+
const status = await client.getCdpStatus();
|
|
62
|
+
if (isMachineFormat(format)) {
|
|
63
|
+
console.log(JSON.stringify(status, null, 2));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (status.connected) {
|
|
67
|
+
console.log(`CDP connected: ${status.endpoint}`);
|
|
68
|
+
if (status.browserVersion) console.log(`Browser: ${status.browserVersion}`);
|
|
69
|
+
if (status.targets?.length) {
|
|
70
|
+
console.log("\nTargets:");
|
|
71
|
+
for (const t of status.targets) {
|
|
72
|
+
const status_label = t.alive ? "\u25CF alive" : "\u25CB idle";
|
|
73
|
+
const lastUsed = t.lastUsed ? ` (last used: ${t.lastUsed})` : "";
|
|
74
|
+
console.log(` ${t.name}: ${status_label}${lastUsed}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
console.log(`CDP not connected at ${status.endpoint}`);
|
|
79
|
+
console.log("Launch Chrome with: chrome --remote-debugging-port=9222");
|
|
80
|
+
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
const msg = describeError(err);
|
|
83
|
+
if (msg.includes("501") || msg.includes("not configured")) {
|
|
84
|
+
if (isMachineFormat(format)) {
|
|
85
|
+
console.log(JSON.stringify({
|
|
86
|
+
connected: false,
|
|
87
|
+
endpoint: "",
|
|
88
|
+
targets: []
|
|
89
|
+
}, null, 2));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
console.log("CDP not configured. Run: canonry cdp connect --host <host> --port <port>");
|
|
93
|
+
} else {
|
|
94
|
+
throw new CliError({
|
|
95
|
+
code: "CDP_STATUS_FAILED",
|
|
96
|
+
message: `Error checking CDP status: ${msg}`,
|
|
97
|
+
displayMessage: `Error checking CDP status: ${msg}`
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function cdpTargets(format) {
|
|
103
|
+
await cdpStatus(format);
|
|
104
|
+
}
|
|
105
|
+
async function cdpScreenshot(query, opts) {
|
|
106
|
+
if (!query) {
|
|
107
|
+
throw new CliError({
|
|
108
|
+
code: "CLI_USAGE_ERROR",
|
|
109
|
+
message: "query is required",
|
|
110
|
+
displayMessage: 'Error: query is required\nUsage: canonry cdp screenshot "best coffee in NYC"',
|
|
111
|
+
details: {
|
|
112
|
+
command: "cdp.screenshot",
|
|
113
|
+
usage: 'canonry cdp screenshot "best coffee in NYC"'
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const client = getClient();
|
|
118
|
+
const body = { query };
|
|
119
|
+
if (opts?.targets) {
|
|
120
|
+
body.targets = opts.targets.split(",").map((s) => s.trim());
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const response = await client.cdpScreenshot(query, body.targets);
|
|
124
|
+
if (isMachineFormat(opts?.format)) {
|
|
125
|
+
console.log(JSON.stringify(response, null, 2));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
for (const r of response.results) {
|
|
129
|
+
console.log(`
|
|
130
|
+
--- ${r.target} ---`);
|
|
131
|
+
console.log(`Screenshot: ${r.screenshotPath}`);
|
|
132
|
+
if (r.citations.length > 0) {
|
|
133
|
+
console.log("Citations:");
|
|
134
|
+
for (const c of r.citations) {
|
|
135
|
+
console.log(` ${c.title}: ${c.uri}`);
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
console.log("No citations found.");
|
|
139
|
+
}
|
|
140
|
+
if (r.answerText) {
|
|
141
|
+
const preview = r.answerText.length > 200 ? r.answerText.slice(0, 200) + "..." : r.answerText;
|
|
142
|
+
console.log(`Answer preview: ${preview}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch (err) {
|
|
146
|
+
const msg = describeError(err);
|
|
147
|
+
throw new CliError({
|
|
148
|
+
code: "CDP_SCREENSHOT_FAILED",
|
|
149
|
+
message: `CDP screenshot failed: ${msg}`,
|
|
150
|
+
displayMessage: `CDP screenshot failed: ${msg}`,
|
|
151
|
+
details: {
|
|
152
|
+
query
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
cdpConnect,
|
|
159
|
+
cdpScreenshot,
|
|
160
|
+
cdpStatus,
|
|
161
|
+
cdpTargets
|
|
162
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// src/mcp/toolkits.ts
|
|
2
|
+
var CANONRY_MCP_TIERS = [
|
|
3
|
+
"core",
|
|
4
|
+
"monitoring",
|
|
5
|
+
"setup",
|
|
6
|
+
"gsc",
|
|
7
|
+
"bing",
|
|
8
|
+
"ga",
|
|
9
|
+
"gbp",
|
|
10
|
+
// `ads` is deliberately OpenAI / ChatGPT Ads. Google Ads has its own
|
|
11
|
+
// toolkit so an agent never mistakes the two provider surfaces.
|
|
12
|
+
"ads",
|
|
13
|
+
"google-ads",
|
|
14
|
+
"gtm",
|
|
15
|
+
"conversion-tracking",
|
|
16
|
+
"traffic",
|
|
17
|
+
"agent",
|
|
18
|
+
"discovery"
|
|
19
|
+
];
|
|
20
|
+
var CANONRY_MCP_TOOLKIT_NAMES = [
|
|
21
|
+
"monitoring",
|
|
22
|
+
"setup",
|
|
23
|
+
"gsc",
|
|
24
|
+
"bing",
|
|
25
|
+
"ga",
|
|
26
|
+
"gbp",
|
|
27
|
+
"ads",
|
|
28
|
+
"google-ads",
|
|
29
|
+
"gtm",
|
|
30
|
+
"conversion-tracking",
|
|
31
|
+
"traffic",
|
|
32
|
+
"agent",
|
|
33
|
+
"discovery"
|
|
34
|
+
];
|
|
35
|
+
var CANONRY_MCP_TOOLKITS = [
|
|
36
|
+
{
|
|
37
|
+
name: "monitoring",
|
|
38
|
+
title: "Measurement, runs, insights, health",
|
|
39
|
+
description: "Inspect portfolio and Property measurement, question results, experimental branded and non-brand sentiment and evidence, content opportunities and addressed-target records, run history, intelligence insights, health timelines, and bounded Site Health reads (overview, page audit evidence, focused subgraphs, paths, and scan changes).",
|
|
40
|
+
whenToLoad: "Load when finding weak Properties, reviewing answers, sentiment and competitors, marking or restoring addressed content targets, checking data quality, tying a Site Health page score to concrete findings, investigating site architecture, comparing scans, or diagnosing regressions."
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "setup",
|
|
44
|
+
title: "Project setup and measurement",
|
|
45
|
+
description: "Manage project configuration, Advanced Measurement drafts, query assets, competitors, and schedules.",
|
|
46
|
+
whenToLoad: "Load when onboarding a project, editing its measurement plan, or managing tracked queries, competitors, or schedules."
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "gsc",
|
|
50
|
+
title: "Google Search Console",
|
|
51
|
+
description: "Read GSC performance, per-query totals, inspections, coverage, sitemaps, and deindexed URLs.",
|
|
52
|
+
whenToLoad: "Load when you need indexing, coverage, or sitemap data from Google Search Console."
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "bing",
|
|
56
|
+
title: "Bing Webmaster Tools",
|
|
57
|
+
description: "Read stored project index coverage and URL inspection evidence without calling Bing.",
|
|
58
|
+
whenToLoad: "Load when reviewing indexed, not indexed or unknown URLs from a connected Bing site."
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "ga",
|
|
62
|
+
title: "Google Analytics 4",
|
|
63
|
+
description: "Read GA traffic, AI/social referral history, attribution trend, session history, and GA4's Search Console landing-page report (Google organic clicks, impressions, CTR, position and active users per landing page).",
|
|
64
|
+
whenToLoad: "Load when you need traffic, referral, or attribution data from Google Analytics 4."
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "gbp",
|
|
68
|
+
title: "Google Business Profile",
|
|
69
|
+
description: "Local AEO signals: discover GBP locations under a connected account and toggle which ones sync, then read daily performance metrics, search keywords, booking links, hotel and owner-set attributes, the public Places listing, and reviews with their alert state.",
|
|
70
|
+
whenToLoad: "Load when the project tracks local search visibility or has connected Google Business Profile."
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "ads",
|
|
74
|
+
title: "OpenAI ads (ChatGPT ads)",
|
|
75
|
+
description: "Live OpenAI ad-account review state, targetable geo IDs, conversion pixels/event settings, synced campaign structure, paid-performance rollups, and guarded lifecycle operations.",
|
|
76
|
+
whenToLoad: "Load when planning, creating, reviewing, or measuring ChatGPT ads, including geo and conversion-readiness checks before launch."
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "google-ads",
|
|
80
|
+
title: "Google Ads conversion evidence",
|
|
81
|
+
description: "Read a connected Google Ads account, its conversion actions, effective campaign goals, and bounded stored snapshots. v1 only reads provider state; it never edits campaigns, conversion actions, or bidding goals.",
|
|
82
|
+
whenToLoad: "Load when selecting a Google Ads customer, reviewing conversion-action and effective-goal evidence, or starting a bounded read-only sync."
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "gtm",
|
|
86
|
+
title: "Google Tag Manager conversion evidence",
|
|
87
|
+
description: "Read GTM accounts, containers, workspaces, and sanitized live/draft tag graphs used to verify a conversion contract. v1 never edits a workspace or publishes a container version.",
|
|
88
|
+
whenToLoad: "Load when selecting a GTM container, reviewing a live or draft conversion-tag graph, or starting a bounded read-only sync."
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "conversion-tracking",
|
|
92
|
+
title: "Cross-provider conversion integrity",
|
|
93
|
+
description: "Read declared conversion contracts and assess them against stored Google Ads and GTM evidence without calling or mutating either provider.",
|
|
94
|
+
whenToLoad: "Load when listing or inspecting declared conversion contracts, or when checking whether stored Google Ads and GTM evidence is consistent with one contract."
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "traffic",
|
|
98
|
+
title: "Server-side traffic ingestion",
|
|
99
|
+
description: "Read complete 7/14/30/90-day traffic analytics and crawler / AI-referral hourly rollups straight from server logs (no GA dependency), assess AI-referral bursts from stored evidence (raw counts, candidate bursts, a separate adjusted estimate, coverage limits), connect Cloud Run / WordPress / Vercel sources, trigger syncs, and backfill Cloud Run / Vercel windows.",
|
|
100
|
+
whenToLoad: "Load when you need server-log evidence of crawler hits or AI-referral sessions (e.g. confirming GPTBot or ChatGPT-User on a page), when reviewing candidate AI-referral bursts before quoting server-side AI referral totals, or when wiring up / syncing a traffic source."
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "agent",
|
|
104
|
+
title: "Aero agent lifecycle and memory",
|
|
105
|
+
description: "Manage the built-in Aero agent: durable project-scoped memory (list/set/forget), clear the rolling transcript, and detach the external-agent webhook.",
|
|
106
|
+
whenToLoad: "Load when reading or writing project-scoped Aero notes, clearing a stuck conversation, or removing an external agent webhook."
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "discovery",
|
|
110
|
+
title: "Query discovery and research",
|
|
111
|
+
description: "Find queries expands an ICP into a promotable tracked-query basket; research queries runs saved free-form experiments against one API model. Research never adds queries to tracking. Prospect snapshots generate a company report without creating a project.",
|
|
112
|
+
whenToLoad: "Load for prospect snapshots, ICP-led candidates for a tracked basket, or research into free-form queries, model answers, sources, and location effects without changing tracking."
|
|
113
|
+
}
|
|
114
|
+
];
|
|
115
|
+
function isCanonryMcpToolkitName(value) {
|
|
116
|
+
return CANONRY_MCP_TOOLKIT_NAMES.includes(value);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
CANONRY_MCP_TIERS,
|
|
121
|
+
CANONRY_MCP_TOOLKIT_NAMES,
|
|
122
|
+
CANONRY_MCP_TOOLKITS,
|
|
123
|
+
isCanonryMcpToolkitName
|
|
124
|
+
};
|