@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,460 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApiClient
|
|
3
|
+
} from "./chunk-V5D4XNWV.js";
|
|
4
|
+
import "./chunk-OFL4PTYU.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-O4RMPA6H.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-V5D4XNWV.js";
|
|
4
|
+
import "./chunk-OFL4PTYU.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-O4RMPA6H.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
|
+
};
|