@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,460 @@
1
+ import {
2
+ createApiClient
3
+ } from "./chunk-B5J675KK.js";
4
+ import "./chunk-UQ3MOZGC.js";
5
+ import {
6
+ emitJsonl
7
+ } from "./chunk-Z7IUAJOF.js";
8
+ import "./chunk-AOJU5LKX.js";
9
+ import {
10
+ CliError,
11
+ isEndpointMissing,
12
+ isMachineFormat,
13
+ usageError
14
+ } from "./chunk-HGMYEDAQ.js";
15
+ import {
16
+ DEFAULT_MEASUREMENT_CONFIG,
17
+ RatioUnits,
18
+ effectiveDomains,
19
+ formatPercent,
20
+ formatSiteAuditPageBudget,
21
+ measurementConfigSchema,
22
+ normalizeProjectAliases,
23
+ normalizeProjectDomain,
24
+ resolveNegativeReviewMaxStars,
25
+ resolveProjectQualifiedAliases
26
+ } from "./chunk-D6COIM3U.js";
27
+ import "./chunk-MLKGABMK.js";
28
+
29
+ // src/commands/project.ts
30
+ function getClient() {
31
+ return createApiClient();
32
+ }
33
+ async function createProject(name, opts) {
34
+ const client = getClient();
35
+ const result = await client.putProject(name, {
36
+ displayName: opts.displayName,
37
+ canonicalDomain: opts.domain,
38
+ ownedDomains: opts.ownedDomains ?? [],
39
+ aliases: normalizeProjectAliases(opts.displayName, opts.aliases ?? []),
40
+ ...opts.qualifiedAliases?.length ? { qualifiedAliases: opts.qualifiedAliases } : {},
41
+ country: opts.country,
42
+ language: opts.language,
43
+ providers: opts.providers ?? [],
44
+ providerModels: opts.providerModels ?? {},
45
+ ...opts.providerDispatchModes && Object.keys(opts.providerDispatchModes).length > 0 ? { providerDispatchModes: opts.providerDispatchModes } : {},
46
+ // Sent only when given: this PUT also re-runs over an existing project,
47
+ // and an omitted budget keeps the stored one.
48
+ ...opts.siteAuditMaxPages !== void 0 ? { siteAuditMaxPages: opts.siteAuditMaxPages } : {}
49
+ });
50
+ warnDroppedDispatchModes(opts.providerDispatchModes ?? {}, result);
51
+ if (isMachineFormat(opts.format)) {
52
+ console.log(JSON.stringify(result, null, 2));
53
+ return;
54
+ }
55
+ console.log(`Project created: ${result.name} (${result.id})`);
56
+ }
57
+ function warnDroppedDispatchModes(sent, result) {
58
+ const kept = result.providerDispatchModes ?? {};
59
+ const dropped = Object.keys(sent).filter((provider) => !(provider in kept));
60
+ if (dropped.length > 0) {
61
+ console.error(`Warning: Dropped dispatch mode for engine(s) the project does not measure: ${dropped.join(", ")}`);
62
+ }
63
+ }
64
+ async function listProjects(format) {
65
+ const client = getClient();
66
+ const projects = await client.listProjects();
67
+ if (format === "json") {
68
+ console.log(JSON.stringify(projects, null, 2));
69
+ return;
70
+ }
71
+ if (format === "jsonl") {
72
+ emitJsonl(projects);
73
+ return;
74
+ }
75
+ if (projects.length === 0) {
76
+ console.log("No projects found.");
77
+ return;
78
+ }
79
+ console.log("Projects:\n");
80
+ const nameWidth = Math.max(4, ...projects.map((p) => p.name.length));
81
+ const domainLabel = (p) => {
82
+ const extra = Math.max(0, effectiveDomains(p).length - 1);
83
+ return extra > 0 ? `${p.canonicalDomain} (+${extra})` : p.canonicalDomain;
84
+ };
85
+ const domainWidth = Math.max(6, ...projects.map((p) => domainLabel(p).length));
86
+ console.log(
87
+ ` ${"NAME".padEnd(nameWidth)} ${"DOMAIN".padEnd(domainWidth)} COUNTRY LANGUAGE`
88
+ );
89
+ console.log(` ${"\u2500".repeat(nameWidth)} ${"\u2500".repeat(domainWidth)} \u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`);
90
+ for (const p of projects) {
91
+ console.log(
92
+ ` ${p.name.padEnd(nameWidth)} ${domainLabel(p).padEnd(domainWidth)} ${p.country.padEnd(7)} ${p.language}`
93
+ );
94
+ }
95
+ }
96
+ function storedQualifiedAliases(project) {
97
+ return project.qualifiedAliases ?? [];
98
+ }
99
+ async function showProject(name, format) {
100
+ const client = getClient();
101
+ const project = await client.getProject(name);
102
+ if (isMachineFormat(format)) {
103
+ console.log(JSON.stringify(project, null, 2));
104
+ return;
105
+ }
106
+ console.log(`Project: ${project.displayName ?? project.name}
107
+ `);
108
+ console.log(` Name: ${project.name}`);
109
+ console.log(` ID: ${project.id}`);
110
+ console.log(` Domain: ${project.canonicalDomain}`);
111
+ const secondaryDomains = effectiveDomains(project).slice(1);
112
+ if (secondaryDomains.length > 0) {
113
+ console.log(` Owned domains: ${secondaryDomains.join(", ")}`);
114
+ }
115
+ if (project.aliases && project.aliases.length > 0) {
116
+ console.log(` Aliases: ${project.aliases.join(", ")}`);
117
+ }
118
+ const qualifiedAliases = storedQualifiedAliases(project);
119
+ if (qualifiedAliases.length > 0) {
120
+ console.log(` Qualified: ${qualifiedAliases.join(", ")} (sentiment)`);
121
+ }
122
+ console.log(` Country: ${project.country}`);
123
+ console.log(` Language: ${project.language}`);
124
+ console.log(` Config source: ${project.configSource}`);
125
+ console.log(` Config revision: ${project.configRevision}`);
126
+ console.log(` Providers: ${(project.providers ?? []).length > 0 ? project.providers.join(", ") : "all configured"}`);
127
+ const providerModels = Object.entries(project.providerModels ?? {});
128
+ console.log(` Model overrides: ${providerModels.length > 0 ? providerModels.map(([provider, model]) => `${provider}=${model}`).join(", ") : "(none; instance settings inherited)"}`);
129
+ const dispatchModes = Object.entries(project.providerDispatchModes ?? {}).sort(([left], [right]) => left.localeCompare(right));
130
+ console.log(` Dispatch modes: ${dispatchModes.length > 0 ? `${dispatchModes.map(([provider, mode]) => `${provider}=${mode}`).join(", ")} (scheduled sweeps; others sync)` : "(none; every provider runs sync)"}`);
131
+ console.log(` Negative reviews: ${resolveNegativeReviewMaxStars(project.negativeReviewMaxStars)} stars or fewer${project.negativeReviewMaxStars == null ? " (default)" : ""}`);
132
+ if (project.siteAuditMaxPages !== void 0) {
133
+ console.log(` Site Health page budget: ${formatSiteAuditPageBudget(project.siteAuditMaxPages)}`);
134
+ }
135
+ if (project.competitorAutoAliases !== void 0) {
136
+ console.log(` Competitor auto aliases: ${formatCompetitorAutoAliasMode(project.competitorAutoAliases)}`);
137
+ }
138
+ if (project.measurement) {
139
+ console.log(` Marketing hosts: ${project.measurement.marketingHosts.length > 0 ? project.measurement.marketingHosts.join(", ") : "(none)"}`);
140
+ console.log(` Brand terms: ${project.measurement.brandTerms.length > 0 ? project.measurement.brandTerms.join(", ") : "(none)"}`);
141
+ console.log(` Lead events: ${project.measurement.leadEventNames.length > 0 ? project.measurement.leadEventNames.join(", ") : "(none)"}`);
142
+ }
143
+ if (project.answerFieldsRecompute !== void 0 && project.answerFieldsRecompute !== null) {
144
+ console.log(` Answer fields recompute: ${project.answerFieldsRecompute}`);
145
+ }
146
+ console.log(` Tags: ${project.tags.length > 0 ? project.tags.join(", ") : "(none)"}`);
147
+ const labelEntries = Object.entries(project.labels);
148
+ console.log(` Labels: ${labelEntries.length > 0 ? labelEntries.map(([k, v]) => `${k}=${v}`).join(", ") : "(none)"}`);
149
+ if (project.createdAt) console.log(` Created: ${project.createdAt}`);
150
+ if (project.updatedAt) console.log(` Updated: ${project.updatedAt}`);
151
+ }
152
+ function formatCompetitorAutoAliasMode(mode) {
153
+ if (mode === "apply") return "apply (names detected after each sweep are stored and counted)";
154
+ if (mode === "off") return "off (no detection after sweeps)";
155
+ return "preview (detected after each sweep and logged; nothing stored)";
156
+ }
157
+ function mergeMeasurementList(current, exact, additions, removals, caseInsensitive, normalizeRemoval) {
158
+ let values = [...exact ?? current];
159
+ if (additions) values.push(...additions);
160
+ if (removals?.length) {
161
+ const normalize = normalizeRemoval ?? ((value) => value);
162
+ const remove = new Set(removals.map((value) => {
163
+ const normalized = normalize(value);
164
+ return caseInsensitive ? normalized.toLowerCase() : normalized;
165
+ }));
166
+ values = values.filter((value) => {
167
+ const normalized = normalize(value);
168
+ return !remove.has(caseInsensitive ? normalized.toLowerCase() : normalized);
169
+ });
170
+ }
171
+ return values;
172
+ }
173
+ function resolveMeasurementUpdate(project, flags) {
174
+ const current = project.measurement ?? DEFAULT_MEASUREMENT_CONFIG;
175
+ const parsed = measurementConfigSchema.safeParse({
176
+ marketingHosts: mergeMeasurementList(current.marketingHosts, flags.marketingHosts, flags.addMarketingHosts, flags.removeMarketingHosts, true, normalizeProjectDomain),
177
+ brandTerms: mergeMeasurementList(current.brandTerms, flags.brandTerms, flags.addBrandTerms, flags.removeBrandTerms, true),
178
+ leadEventNames: mergeMeasurementList(current.leadEventNames, flags.leadEvents, flags.addLeadEvents, flags.removeLeadEvents, false)
179
+ });
180
+ if (!parsed.success) {
181
+ const issue = parsed.error.issues[0];
182
+ throw usageError(`Error: invalid measurement option${issue?.message ? `: ${issue.message}` : ""}`, {
183
+ message: issue?.message ?? "invalid measurement option",
184
+ details: { command: "project.update", path: issue?.path.join(".") ?? "" }
185
+ });
186
+ }
187
+ return parsed.data;
188
+ }
189
+ async function updateProjectSettings(name, opts) {
190
+ const client = getClient();
191
+ const project = await client.getProject(name);
192
+ if (opts.expectedConfigRevision !== void 0 && opts.expectedConfigRevision !== project.configRevision) {
193
+ throw new CliError({
194
+ code: "PROJECT_REVISION_CONFLICT",
195
+ message: `Project '${name}' has revision ${project.configRevision}, not the expected ${opts.expectedConfigRevision}.`,
196
+ details: { expected: opts.expectedConfigRevision, actual: project.configRevision }
197
+ });
198
+ }
199
+ if (opts.dryRun) {
200
+ const hasValue = (key, value) => {
201
+ if (value === void 0) return false;
202
+ if (value === null) return true;
203
+ if (Array.isArray(value)) return key === "providers" || value.length > 0;
204
+ if (typeof value === "object") return Object.keys(value).length > 0;
205
+ return true;
206
+ };
207
+ const changedKeys = Object.entries(opts).filter(([key, value]) => key !== "dryRun" && key !== "format" && hasValue(key, value));
208
+ if (opts.competitorAutoAliases !== "apply" || changedKeys.some(([key]) => key !== "competitorAutoAliases")) {
209
+ throw usageError("Error: project update --dry-run supports only --competitor-auto-aliases apply", {
210
+ message: "--dry-run supports only --competitor-auto-aliases apply",
211
+ details: { command: "project.update", project: name }
212
+ });
213
+ }
214
+ const detection = await client.previewCompetitorAutoAliases(name);
215
+ const preview = {
216
+ dryRun: true,
217
+ project: name,
218
+ modeBefore: project.competitorAutoAliases ?? "preview",
219
+ modeAfter: opts.competitorAutoAliases,
220
+ impact: detection.impact
221
+ };
222
+ if (isMachineFormat(opts.format)) {
223
+ console.log(JSON.stringify(preview, null, 2));
224
+ } else {
225
+ console.log(`Competitor auto-alias mode preview: ${preview.modeBefore} -> ${preview.modeAfter}`);
226
+ const percentBefore = detection.impact?.before.percent;
227
+ const percentAfter = detection.impact?.after.percent;
228
+ console.log(`Mention share ${percentBefore === null || percentBefore === void 0 ? "not measured" : formatPercent(percentBefore, RatioUnits.percent)} -> ${percentAfter === null || percentAfter === void 0 ? "not measured" : formatPercent(percentAfter, RatioUnits.percent)} (stored evidence preview)`);
229
+ }
230
+ return;
231
+ }
232
+ let ownedDomains = opts.ownedDomains ?? project.ownedDomains ?? [];
233
+ if (opts.addOwnedDomain) {
234
+ const toAdd = opts.addOwnedDomain.filter((d) => !ownedDomains.includes(d));
235
+ ownedDomains = [...ownedDomains, ...toAdd];
236
+ }
237
+ if (opts.removeOwnedDomain) {
238
+ const toRemove = new Set(opts.removeOwnedDomain);
239
+ ownedDomains = ownedDomains.filter((d) => !toRemove.has(d));
240
+ }
241
+ const nextDisplayName = opts.displayName ?? project.displayName ?? project.name;
242
+ let aliases = opts.aliases ?? project.aliases ?? [];
243
+ if (opts.addAlias) {
244
+ const existingKeys = new Set(aliases.map((a) => a.toLowerCase()));
245
+ const toAdd = opts.addAlias.filter((a) => !existingKeys.has(a.toLowerCase()));
246
+ aliases = [...aliases, ...toAdd];
247
+ }
248
+ if (opts.removeAlias) {
249
+ const toRemove = new Set(opts.removeAlias.map((a) => a.toLowerCase()));
250
+ aliases = aliases.filter((a) => !toRemove.has(a.toLowerCase()));
251
+ }
252
+ const nextAliases = normalizeProjectAliases(nextDisplayName, aliases);
253
+ const touchesQualified = (opts.addQualifiedAlias?.length ?? 0) > 0 || (opts.removeQualifiedAlias?.length ?? 0) > 0;
254
+ let qualifiedAliases = resolveProjectQualifiedAliases(
255
+ { displayName: nextDisplayName, aliases: nextAliases },
256
+ storedQualifiedAliases(project)
257
+ ).value;
258
+ if (opts.addQualifiedAlias) {
259
+ const existingKeys = new Set(qualifiedAliases.map((alias) => alias.toLowerCase()));
260
+ for (const alias of opts.addQualifiedAlias) {
261
+ if (existingKeys.has(alias.toLowerCase())) continue;
262
+ existingKeys.add(alias.toLowerCase());
263
+ qualifiedAliases = [...qualifiedAliases, alias];
264
+ }
265
+ }
266
+ if (opts.removeQualifiedAlias) {
267
+ const toRemove = new Set(opts.removeQualifiedAlias.map((alias) => alias.toLowerCase()));
268
+ qualifiedAliases = qualifiedAliases.filter((alias) => !toRemove.has(alias.toLowerCase()));
269
+ }
270
+ const providerModels = { ...project.providerModels ?? {}, ...opts.providerModels ?? {} };
271
+ for (const provider of opts.clearProviderModels ?? []) delete providerModels[provider];
272
+ const nextProviders = opts.providers ?? project.providers ?? [];
273
+ if (nextProviders.length > 0) {
274
+ const requested = Object.keys(opts.providerModels ?? {}).filter((p) => !nextProviders.includes(p));
275
+ if (requested.length > 0) {
276
+ throw usageError(
277
+ `Error: --provider-model set for ${requested.join(", ")}, which ${requested.length > 1 ? "are" : "is"} not a selected engine for "${name}"`,
278
+ {
279
+ message: "provider-model set for a provider the project does not run",
280
+ details: { command: "project.update", project: name, providers: nextProviders, unselected: requested }
281
+ }
282
+ );
283
+ }
284
+ }
285
+ const touchesDispatch = Object.keys(opts.dispatchModes ?? {}).length > 0 || (opts.clearDispatchModes ?? []).length > 0;
286
+ const providerDispatchModes = { ...project.providerDispatchModes ?? {}, ...opts.dispatchModes ?? {} };
287
+ for (const provider of opts.clearDispatchModes ?? []) delete providerDispatchModes[provider];
288
+ const patch = {
289
+ expectedConfigRevision: opts.expectedConfigRevision ?? project.configRevision,
290
+ ...opts.displayName !== void 0 ? { displayName: nextDisplayName } : {},
291
+ ...opts.domain !== void 0 ? { canonicalDomain: opts.domain } : {},
292
+ ...opts.ownedDomains !== void 0 || opts.addOwnedDomain !== void 0 || opts.removeOwnedDomain !== void 0 ? { ownedDomains } : {},
293
+ ...opts.aliases !== void 0 || opts.addAlias !== void 0 || opts.removeAlias !== void 0 ? { aliases: nextAliases } : {},
294
+ ...opts.country !== void 0 ? { country: opts.country } : {},
295
+ ...opts.language !== void 0 ? { language: opts.language } : {},
296
+ ...opts.providers !== void 0 ? { providers: opts.providers } : {},
297
+ ...Object.keys(opts.providerModels ?? {}).length > 0 || (opts.clearProviderModels?.length ?? 0) > 0 ? { providerModels } : {},
298
+ ...touchesQualified ? { qualifiedAliases } : {},
299
+ ...touchesDispatch ? { providerDispatchModes } : {},
300
+ ...opts.negativeReviewMaxStars !== void 0 ? { negativeReviewMaxStars: opts.negativeReviewMaxStars } : {},
301
+ ...opts.siteAuditMaxPages !== void 0 ? { siteAuditMaxPages: opts.siteAuditMaxPages } : {},
302
+ ...opts.competitorAutoAliases !== void 0 ? { competitorAutoAliases: opts.competitorAutoAliases } : {},
303
+ ...opts.measurement !== void 0 ? { measurement: resolveMeasurementUpdate(project, opts.measurement) } : {}
304
+ };
305
+ let result;
306
+ try {
307
+ result = await client.patchProject(name, patch);
308
+ } catch (error) {
309
+ if (!(error instanceof CliError) || !isEndpointMissing(error)) throw error;
310
+ if (error.details?.httpStatus !== 405 && !/route/i.test(error.message)) throw error;
311
+ const latest = await client.getProject(name);
312
+ if (latest.configRevision !== project.configRevision) {
313
+ throw new CliError({
314
+ code: "PROJECT_REVISION_CONFLICT",
315
+ message: `Project '${name}' changed while the PATCH endpoint was unavailable. Re-read it and retry.`,
316
+ details: { expected: project.configRevision, actual: latest.configRevision }
317
+ });
318
+ }
319
+ const legacyBody = {
320
+ displayName: nextDisplayName,
321
+ canonicalDomain: opts.domain ?? project.canonicalDomain,
322
+ ownedDomains,
323
+ aliases: nextAliases,
324
+ ...touchesQualified ? { qualifiedAliases } : {},
325
+ country: opts.country ?? project.country,
326
+ language: opts.language ?? project.language,
327
+ tags: project.tags,
328
+ labels: project.labels,
329
+ providers: opts.providers ?? project.providers,
330
+ providerModels,
331
+ ...touchesDispatch ? { providerDispatchModes } : {},
332
+ locations: project.locations,
333
+ defaultLocation: project.defaultLocation,
334
+ autoExtractBacklinks: project.autoExtractBacklinks,
335
+ ...opts.negativeReviewMaxStars !== void 0 ? { negativeReviewMaxStars: opts.negativeReviewMaxStars } : {},
336
+ ...opts.siteAuditMaxPages !== void 0 ? { siteAuditMaxPages: opts.siteAuditMaxPages } : {},
337
+ ...opts.competitorAutoAliases !== void 0 ? { competitorAutoAliases: opts.competitorAutoAliases } : {},
338
+ ...opts.measurement !== void 0 ? { measurement: resolveMeasurementUpdate(project, opts.measurement) } : {}
339
+ };
340
+ result = await client.putProject(name, legacyBody);
341
+ }
342
+ warnDroppedDispatchModes(touchesDispatch ? providerDispatchModes : project.providerDispatchModes ?? {}, result);
343
+ if (isMachineFormat(opts.format)) {
344
+ console.log(JSON.stringify(result, null, 2));
345
+ return;
346
+ }
347
+ console.log(`Project updated: ${result.name}`);
348
+ const dropped = Object.keys(providerModels).filter((provider) => !(provider in result.providerModels));
349
+ if (dropped.length > 0) {
350
+ console.log(` Dropped model override for deselected engine(s): ${dropped.join(", ")}`);
351
+ }
352
+ }
353
+ async function deleteProject(name, opts) {
354
+ const client = getClient();
355
+ const isJson = isMachineFormat(opts?.format);
356
+ if (opts?.dryRun) {
357
+ const preview = await client.previewProjectDelete(name);
358
+ if (isJson) {
359
+ console.log(JSON.stringify({ dryRun: true, ...preview }, null, 2));
360
+ return;
361
+ }
362
+ const { cascadeRows: cr, detachedRows: dr } = preview;
363
+ console.log(`Project delete preview for "${name}":`);
364
+ console.log(` Cascade-deletes:`);
365
+ console.log(` queries: ${cr.queries}`);
366
+ console.log(` competitors: ${cr.competitors}`);
367
+ console.log(` runs: ${cr.runs}`);
368
+ console.log(` snapshots: ${cr.snapshots}`);
369
+ console.log(` insights: ${cr.insights}`);
370
+ console.log(` Detached (project_id set to NULL):`);
371
+ console.log(` audit_log: ${dr.auditLog}`);
372
+ console.log(``);
373
+ console.log(`No DB writes performed. Re-run without --dry-run to delete.`);
374
+ return;
375
+ }
376
+ await client.deleteProject(name);
377
+ if (isJson) {
378
+ console.log(JSON.stringify({ name, deleted: true }, null, 2));
379
+ return;
380
+ }
381
+ console.log(`Project deleted: ${name}`);
382
+ }
383
+ async function addLocation(project, opts) {
384
+ const client = getClient();
385
+ const location = await client.addLocation(project, {
386
+ label: opts.label,
387
+ city: opts.city,
388
+ region: opts.region,
389
+ country: opts.country,
390
+ timezone: opts.timezone
391
+ });
392
+ if (isMachineFormat(opts.format)) {
393
+ console.log(JSON.stringify(location, null, 2));
394
+ return;
395
+ }
396
+ console.log(`Location added: ${opts.label} (${opts.city}, ${opts.region}, ${opts.country})`);
397
+ }
398
+ async function listLocations(project, format) {
399
+ const client = getClient();
400
+ const result = await client.listLocations(project);
401
+ if (format === "json") {
402
+ console.log(JSON.stringify(result, null, 2));
403
+ return;
404
+ }
405
+ if (format === "jsonl") {
406
+ emitJsonl(result.locations.map((loc) => ({
407
+ project,
408
+ isDefault: loc.label === result.defaultLocation,
409
+ ...loc
410
+ })));
411
+ return;
412
+ }
413
+ if (result.locations.length === 0) {
414
+ console.log(`No locations configured for "${project}".`);
415
+ return;
416
+ }
417
+ console.log(`Locations for "${project}" (${result.locations.length}):
418
+ `);
419
+ console.log(" LABEL CITY REGION COUNTRY DEFAULT");
420
+ console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500");
421
+ for (const loc of result.locations) {
422
+ const isDefault = loc.label === result.defaultLocation ? " *" : "";
423
+ console.log(
424
+ ` ${loc.label.padEnd(15)} ${loc.city.padEnd(19)} ${loc.region.padEnd(19)} ${loc.country.padEnd(7)}${isDefault}`
425
+ );
426
+ }
427
+ if (result.defaultLocation) {
428
+ console.log(`
429
+ Default: ${result.defaultLocation}`);
430
+ }
431
+ }
432
+ async function removeLocation(project, label, format) {
433
+ const client = getClient();
434
+ await client.removeLocation(project, label);
435
+ if (isMachineFormat(format)) {
436
+ console.log(JSON.stringify({ project, label, removed: true }, null, 2));
437
+ return;
438
+ }
439
+ console.log(`Location removed: ${label}`);
440
+ }
441
+ async function setDefaultLocation(project, label, format) {
442
+ const client = getClient();
443
+ const result = await client.setDefaultLocation(project, label);
444
+ if (isMachineFormat(format)) {
445
+ console.log(JSON.stringify({ project, ...result }, null, 2));
446
+ return;
447
+ }
448
+ console.log(`Default location set to: ${label}`);
449
+ }
450
+ export {
451
+ addLocation,
452
+ createProject,
453
+ deleteProject,
454
+ listLocations,
455
+ listProjects,
456
+ removeLocation,
457
+ setDefaultLocation,
458
+ showProject,
459
+ updateProjectSettings
460
+ };
@@ -0,0 +1,211 @@
1
+ import {
2
+ createApiClient
3
+ } from "./chunk-B5J675KK.js";
4
+ import "./chunk-UQ3MOZGC.js";
5
+ import {
6
+ emitJsonl
7
+ } from "./chunk-Z7IUAJOF.js";
8
+ import "./chunk-AOJU5LKX.js";
9
+ import {
10
+ CliError,
11
+ isMachineFormat
12
+ } from "./chunk-HGMYEDAQ.js";
13
+ import {
14
+ reportedQueryClasses
15
+ } from "./chunk-D6COIM3U.js";
16
+ import "./chunk-MLKGABMK.js";
17
+
18
+ // src/commands/query.ts
19
+ import fs from "fs";
20
+ function getClient() {
21
+ return createApiClient();
22
+ }
23
+ var NO_CLASS = "-";
24
+ var CLASS_COLUMN_WIDTH = "non-brand".length;
25
+ var NO_CLASS_NOTE = `${NO_CLASS} = no class: the project has no usable brand name, or its measurement plan holds no single class for that query (canonry query workspace shows the class per Property).`;
26
+ var CLASS_NOT_REPORTED_NOTE = `${NO_CLASS} = class not reported: this server version does not send a query class. Upgrade the server to see it.`;
27
+ function classCell(queryClass) {
28
+ return (queryClass ?? NO_CLASS).padEnd(CLASS_COLUMN_WIDTH);
29
+ }
30
+ function dashNotes(rows) {
31
+ return [
32
+ ...rows.some((row) => row.queryClass === null) ? [NO_CLASS_NOTE] : [],
33
+ ...rows.some((row) => row.queryClass === void 0) ? [CLASS_NOT_REPORTED_NOTE] : []
34
+ ];
35
+ }
36
+ async function addQueries(project, queries, format) {
37
+ const client = getClient();
38
+ const queryClasses = reportedQueryClasses(queries, await client.appendQueries(project, queries));
39
+ if (isMachineFormat(format)) {
40
+ console.log(JSON.stringify({
41
+ project,
42
+ queries,
43
+ addedCount: queries.length,
44
+ queryClasses
45
+ }, null, 2));
46
+ return;
47
+ }
48
+ console.log(`Added ${queries.length} ${queries.length === 1 ? "query" : "queries"} to "${project}".`);
49
+ for (const entry of queryClasses) {
50
+ console.log(` ${classCell(entry.queryClass)} ${entry.query}`);
51
+ }
52
+ for (const note of dashNotes(queryClasses)) console.log(` ${note}`);
53
+ }
54
+ async function replaceQueries(project, queries, opts) {
55
+ const client = getClient();
56
+ const isJson = isMachineFormat(opts?.format);
57
+ if (opts?.dryRun) {
58
+ const preview = await client.previewReplaceQueries(project, queries);
59
+ if (isJson) {
60
+ console.log(JSON.stringify({ dryRun: true, ...preview }, null, 2));
61
+ return;
62
+ }
63
+ const { diff, snapshotImpact } = preview;
64
+ console.log(`Query replace preview for "${project}":`);
65
+ console.log(` Current: ${preview.current.length} ${preview.current.length === 1 ? "query" : "queries"}`);
66
+ console.log(` Proposed: ${preview.proposed.length} ${preview.proposed.length === 1 ? "query" : "queries"}`);
67
+ console.log(` Diff:`);
68
+ console.log(` + added: ${diff.added.length}${diff.added.length ? ` (${diff.added.join(", ")})` : ""}`);
69
+ console.log(` - removed: ${diff.removed.length}${diff.removed.length ? ` (${diff.removed.join(", ")})` : ""}`);
70
+ console.log(` = unchanged: ${diff.unchanged.length}${diff.unchanged.length ? ` (${diff.unchanged.join(", ")})` : ""}`);
71
+ console.log(` Snapshot impact:`);
72
+ console.log(` Replace wipes every queries row and re-inserts with new IDs, so ALL`);
73
+ console.log(` existing snapshots get detached (queryId \u2192 NULL; queryText preserved).`);
74
+ console.log(` Snapshots affected: ${snapshotImpact.snapshotsDetached} across ${snapshotImpact.affectedQueries} ${snapshotImpact.affectedQueries === 1 ? "query" : "queries"}`);
75
+ console.log(``);
76
+ console.log(`No DB writes performed. Re-run without --dry-run to apply.`);
77
+ return;
78
+ }
79
+ await client.putQueries(project, queries);
80
+ if (isJson) {
81
+ console.log(JSON.stringify({
82
+ project,
83
+ queries,
84
+ replacedCount: queries.length
85
+ }, null, 2));
86
+ return;
87
+ }
88
+ console.log(`Set ${queries.length} ${queries.length === 1 ? "query" : "queries"} for "${project}".`);
89
+ }
90
+ async function removeQueries(project, queries, format) {
91
+ const client = getClient();
92
+ const existing = await client.listQueries(project);
93
+ const existingSet = new Set(existing.map((q) => q.query));
94
+ const removedQueries = queries.filter((q) => existingSet.has(q));
95
+ await client.deleteQueries(project, queries);
96
+ if (isMachineFormat(format)) {
97
+ console.log(JSON.stringify({
98
+ project,
99
+ queries,
100
+ removedQueries,
101
+ removedCount: removedQueries.length
102
+ }, null, 2));
103
+ return;
104
+ }
105
+ console.log(`Removed ${removedQueries.length} ${removedQueries.length === 1 ? "query" : "queries"} from "${project}".`);
106
+ }
107
+ async function listQueries(project, format) {
108
+ const client = getClient();
109
+ const qs = await client.listQueries(project);
110
+ if (format === "json") {
111
+ console.log(JSON.stringify(qs, null, 2));
112
+ return;
113
+ } else if (format === "jsonl") {
114
+ emitJsonl(qs.map((q) => ({ project, ...q })));
115
+ return;
116
+ }
117
+ if (qs.length === 0) {
118
+ console.log(`No queries found for "${project}".`);
119
+ return;
120
+ }
121
+ console.log(`Queries for "${project}" (${qs.length}):
122
+ `);
123
+ console.log(` ${"CLASS".padEnd(CLASS_COLUMN_WIDTH)} QUERY`);
124
+ for (const q of qs) {
125
+ console.log(` ${classCell(q.queryClass)} ${q.query}`);
126
+ }
127
+ const notes = dashNotes(qs);
128
+ if (notes.length > 0) console.log(`
129
+ ${notes.map((note) => ` ${note}`).join("\n")}`);
130
+ }
131
+ async function importQueries(project, filePath, format) {
132
+ if (!fs.existsSync(filePath)) {
133
+ throw new CliError({
134
+ code: "QUERY_IMPORT_FILE_NOT_FOUND",
135
+ message: `File not found: ${filePath}`,
136
+ displayMessage: `Error: file not found: ${filePath}`,
137
+ details: {
138
+ project,
139
+ filePath
140
+ }
141
+ });
142
+ }
143
+ const content = fs.readFileSync(filePath, "utf-8");
144
+ const queries = content.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
145
+ if (queries.length === 0) {
146
+ if (isMachineFormat(format)) {
147
+ console.log(JSON.stringify({
148
+ project,
149
+ filePath,
150
+ queries: [],
151
+ importedCount: 0
152
+ }, null, 2));
153
+ return;
154
+ }
155
+ console.log("No queries found in file.");
156
+ return;
157
+ }
158
+ const client = getClient();
159
+ await client.appendQueries(project, queries);
160
+ if (isMachineFormat(format)) {
161
+ console.log(JSON.stringify({
162
+ project,
163
+ filePath,
164
+ queries,
165
+ importedCount: queries.length
166
+ }, null, 2));
167
+ return;
168
+ }
169
+ console.log(`Imported ${queries.length} ${queries.length === 1 ? "query" : "queries"} to "${project}".`);
170
+ }
171
+ async function generateQueries(project, provider, opts) {
172
+ const client = getClient();
173
+ const result = await client.generateQueries(project, provider, opts.count);
174
+ const saved = Boolean(opts.save && result.queries.length > 0);
175
+ if (!isMachineFormat(opts.format)) {
176
+ console.log(`Generated ${result.queries.length} ${result.queries.length === 1 ? "query" : "queries"} using ${result.provider}:
177
+ `);
178
+ for (const q of result.queries) {
179
+ console.log(` ${q}`);
180
+ }
181
+ if (result.queries.length > 0 && !saved) {
182
+ console.log(`
183
+ To add these, run: canonry query add ${project} <query>...`);
184
+ }
185
+ }
186
+ if (saved) {
187
+ await client.appendQueries(project, result.queries);
188
+ if (!isMachineFormat(opts.format)) {
189
+ console.log(`
190
+ Saved ${result.queries.length} ${result.queries.length === 1 ? "query" : "queries"} to "${project}".`);
191
+ }
192
+ }
193
+ if (isMachineFormat(opts.format)) {
194
+ console.log(JSON.stringify({
195
+ project,
196
+ provider: result.provider,
197
+ queries: result.queries,
198
+ generatedCount: result.queries.length,
199
+ saved,
200
+ savedCount: saved ? result.queries.length : 0
201
+ }, null, 2));
202
+ }
203
+ }
204
+ export {
205
+ addQueries,
206
+ generateQueries,
207
+ importQueries,
208
+ listQueries,
209
+ removeQueries,
210
+ replaceQueries
211
+ };