agentic-commerce-readiness 0.0.0-stage → 0.1.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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +200 -2
- package/bin/agentic-commerce-readiness.js +100 -0
- package/package.json +56 -4
- package/src/feed/export.js +109 -0
- package/src/feed/parse.js +259 -0
- package/src/feed/validate.js +337 -0
- package/src/feed/values.js +182 -0
- package/src/index.js +123 -0
- package/src/live/catalog.js +131 -0
- package/src/live/consistency.js +135 -0
- package/src/live/discovery.js +149 -0
- package/src/live/http.js +28 -0
- package/src/report.js +128 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Discovery documents that AI shopping agents read before transacting.
|
|
2
|
+
// UCP: /.well-known/ucp (Universal Commerce Protocol, ucp.dev/latest/specification/overview)
|
|
3
|
+
// ACP: /.well-known/acp.json (Agentic Commerce Protocol discovery document; proposal stage)
|
|
4
|
+
// A2A: /.well-known/agent-card.json (only relevant if the store runs its own agent)
|
|
5
|
+
|
|
6
|
+
import { get } from './http.js';
|
|
7
|
+
import { parseRobots, isAllowed } from 'ai-ready-audit';
|
|
8
|
+
|
|
9
|
+
const DATE_RE = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
10
|
+
const TRANSPORTS = new Set(['rest', 'mcp', 'a2a', 'embedded']);
|
|
11
|
+
const isHttpsUrl = (s) => { try { return new URL(s).protocol === 'https:'; } catch { return false; } };
|
|
12
|
+
|
|
13
|
+
/** Validate a UCP business profile response. Pure function, so it can be tested without network. */
|
|
14
|
+
export function validateUcpProfile({ status, headers, text, url }) {
|
|
15
|
+
const findings = [];
|
|
16
|
+
const add = (severity, message, fix) => findings.push({ severity, message, fix });
|
|
17
|
+
if (status >= 300 && status < 400) {
|
|
18
|
+
add('error', `Profile redirects (HTTP ${status})`, 'Serve /.well-known/ucp directly. The spec forbids redirects on profile endpoints.');
|
|
19
|
+
return { present: true, valid: false, findings };
|
|
20
|
+
}
|
|
21
|
+
if (status === 404 || status === 410) return { present: false, valid: false, findings };
|
|
22
|
+
if (status !== 200) {
|
|
23
|
+
add('error', `Profile returned HTTP ${status}`, 'Return 200 with the JSON profile.');
|
|
24
|
+
return { present: true, valid: false, findings };
|
|
25
|
+
}
|
|
26
|
+
if (url && !url.startsWith('https://')) add('error', 'Profile is not served over HTTPS', 'Serve the profile over HTTPS.');
|
|
27
|
+
const cc = (headers.get('cache-control') || '').toLowerCase();
|
|
28
|
+
const maxAge = /max-age=(\d+)/.exec(cc);
|
|
29
|
+
if (!cc) add('error', 'No Cache-Control header', 'Send Cache-Control: public, max-age=3600 (at least 60 seconds is required).');
|
|
30
|
+
else {
|
|
31
|
+
if (!/\bpublic\b/.test(cc)) add('error', `Cache-Control "${cc}" lacks "public"`, 'Include "public".');
|
|
32
|
+
if (!maxAge || Number(maxAge[1]) < 60) add('error', `Cache-Control "${cc}" needs max-age of at least 60`, 'Use max-age=3600 or similar.');
|
|
33
|
+
if (/\b(private|no-store|no-cache)\b/.test(cc)) add('error', `Cache-Control "${cc}" uses private, no-store or no-cache`, 'These are not allowed on UCP profiles.');
|
|
34
|
+
}
|
|
35
|
+
if (!headers.get('etag') && !headers.get('last-modified')) add('warning', 'No ETag or Last-Modified header', 'Add a validator so agents can revalidate cheaply.');
|
|
36
|
+
if (Buffer.byteLength(text || '') > 128 * 1024) add('warning', 'Profile is larger than 128 KiB', 'The UCP spec lets verifiers cap profiles at 128 KiB, so agents may cut this one off. Published examples are under 5 KiB: move large data out of the profile.');
|
|
37
|
+
|
|
38
|
+
let doc;
|
|
39
|
+
try { doc = JSON.parse(text); } catch (e) {
|
|
40
|
+
add('error', `Profile is not valid JSON (${e.message})`, 'Fix the JSON syntax.');
|
|
41
|
+
return { present: true, valid: false, findings };
|
|
42
|
+
}
|
|
43
|
+
const ucp = doc?.ucp;
|
|
44
|
+
if (!ucp || typeof ucp !== 'object') {
|
|
45
|
+
add('error', 'Missing top-level "ucp" object', 'The profile must have a "ucp" object with version, services and payment_handlers.');
|
|
46
|
+
return { present: true, valid: false, findings, doc };
|
|
47
|
+
}
|
|
48
|
+
if (!ucp.version) add('error', 'Missing ucp.version', 'Set ucp.version to the protocol version, in YYYY-MM-DD form.');
|
|
49
|
+
else if (!DATE_RE.test(String(ucp.version))) add('error', `ucp.version "${ucp.version}" is not YYYY-MM-DD`, 'Use the release date format, for example 2026-08-25.');
|
|
50
|
+
if (ucp.services === undefined) add('error', 'Missing ucp.services', 'Include "services": {} even when empty; the spec requires the registry to be present.');
|
|
51
|
+
else if (typeof ucp.services !== 'object' || Array.isArray(ucp.services)) add('error', 'ucp.services must be an object keyed by service name', 'Use {"dev.ucp.shopping": [ ...bindings ]}.');
|
|
52
|
+
else {
|
|
53
|
+
if (!Object.keys(ucp.services).length) add('warning', 'ucp.services is empty', 'Add the dev.ucp.shopping service so agents can shop with you.');
|
|
54
|
+
else if (!ucp.services['dev.ucp.shopping']) add('warning', 'No dev.ucp.shopping service', 'Shopping agents look for the dev.ucp.shopping service.');
|
|
55
|
+
for (const [name, bindings] of Object.entries(ucp.services)) {
|
|
56
|
+
if (!Array.isArray(bindings)) { add('error', `Service "${name}" must be an array of transport bindings`, 'Each transport is a separate array entry with a "transport" field.'); continue; }
|
|
57
|
+
bindings.forEach((b, i) => {
|
|
58
|
+
const where = `${name}[${i}]`;
|
|
59
|
+
if (!b.version || !DATE_RE.test(String(b.version))) add('error', `${where}: missing or invalid version`, 'Use YYYY-MM-DD.');
|
|
60
|
+
if (!b.spec) add('error', `${where}: missing spec URL`, 'Link the human-readable spec.');
|
|
61
|
+
if (!TRANSPORTS.has(b.transport)) add('error', `${where}: transport must be rest, mcp, a2a or embedded (got "${b.transport}")`, 'Set a valid transport.');
|
|
62
|
+
if (['rest', 'mcp', 'embedded'].includes(b.transport) && !b.schema) add('error', `${where}: ${b.transport} binding needs a schema`, 'Add the schema URL.');
|
|
63
|
+
if (['rest', 'mcp', 'a2a'].includes(b.transport)) {
|
|
64
|
+
if (!b.endpoint) add('warning', `${where}: no endpoint for the ${b.transport} binding`, 'Add the base URL (REST/MCP) or Agent Card URL (A2A).');
|
|
65
|
+
else if (!isHttpsUrl(b.endpoint)) add('error', `${where}: endpoint is not an https URL`, 'Use an https endpoint.');
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (ucp.payment_handlers === undefined) add('error', 'Missing ucp.payment_handlers', 'Include "payment_handlers": {} even when empty; the spec requires it.');
|
|
71
|
+
else if (typeof ucp.payment_handlers !== 'object' || Array.isArray(ucp.payment_handlers)) add('error', 'ucp.payment_handlers must be an object keyed by handler name', 'Use {"com.example.processor": [ { "id": ..., "version": ..., "spec": ..., "schema": ... } ]}, or {} when you have none.');
|
|
72
|
+
else for (const [name, entries] of Object.entries(ucp.payment_handlers)) {
|
|
73
|
+
const list = Array.isArray(entries) ? entries : [entries];
|
|
74
|
+
list.forEach((h, i) => {
|
|
75
|
+
if (!h || typeof h !== 'object') { add('error', `Payment handler "${name}" entry ${i} is not an object`, 'Each handler entry is an object.'); return; }
|
|
76
|
+
for (const f of ['id', 'version', 'spec']) if (!h[f]) add('warning', `Payment handler "${name}" is missing ${f}`, `Add ${f} so agents can negotiate this handler.`);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (ucp.capabilities !== undefined) {
|
|
80
|
+
if (typeof ucp.capabilities !== 'object' || Array.isArray(ucp.capabilities)) add('error', 'ucp.capabilities must be an object keyed by capability name', 'Use {"dev.ucp.shopping.checkout": [ { "version": ..., "spec": ..., "schema": ... } ]}.');
|
|
81
|
+
else for (const [name, value] of Object.entries(ucp.capabilities)) {
|
|
82
|
+
// Current spec (2026-08-25): an array of entries. Earlier drafts used a single object; accept both.
|
|
83
|
+
const list = Array.isArray(value) ? value : [value];
|
|
84
|
+
if (!list.length) add('warning', `Capability "${name}" has no entries`, 'Add at least one version entry or remove the capability.');
|
|
85
|
+
list.forEach((c) => {
|
|
86
|
+
for (const f of ['version', 'spec', 'schema']) if (!c?.[f]) add('error', `Capability "${name}" is missing ${f}`, `Add ${f}.`);
|
|
87
|
+
if (c?.version && !DATE_RE.test(String(c.version))) add('error', `Capability "${name}" version "${c.version}" is not YYYY-MM-DD`, 'Use the release date format.');
|
|
88
|
+
if (c?.extends && !ucp.capabilities[c.extends]) add('warning', `Capability "${name}" extends "${c.extends}", which the profile does not declare`, `Declare ${c.extends} too, or agents may ignore this extension.`);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (ucp.keys !== undefined) add('error', '"keys" is inside "ucp"', 'Move "keys" to the top level of the profile, next to "ucp" (not inside it).');
|
|
93
|
+
if (doc.keys !== undefined) {
|
|
94
|
+
const keys = Array.isArray(doc.keys) ? doc.keys : doc.keys?.keys;
|
|
95
|
+
if (!Array.isArray(keys)) add('error', '"keys" is not a JWK Set', 'Publish signing keys as a JWK Set.');
|
|
96
|
+
else keys.forEach((k, i) => {
|
|
97
|
+
if (!k.kty || !k.kid) add('warning', `keys[${i}] lacks kty or kid`, 'Each JWK needs kty and kid.');
|
|
98
|
+
// Private JWK members (RFC 7518): d for EC/OKP/RSA, plus RSA CRT parts, and k for symmetric keys.
|
|
99
|
+
const priv = ['d', 'p', 'q', 'dp', 'dq', 'qi', 'k'].filter((m) => k[m] !== undefined);
|
|
100
|
+
if (priv.length) add('error', `keys[${i}] (${k.kid || 'no kid'}) contains PRIVATE key material (${priv.join(', ')})`, 'Remove it now and rotate this key: anyone can sign as your store. Publish only the public part (kty, crv, x, y or n, e).');
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return { present: true, valid: !findings.some((f) => f.severity === 'error'), findings, doc };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function validateAcpDiscovery({ status, text }) {
|
|
107
|
+
const findings = [];
|
|
108
|
+
if (status === 404 || status === 410) return { present: false, findings };
|
|
109
|
+
if (status !== 200) return { present: true, findings: [{ severity: 'warning', message: `/.well-known/acp.json returned HTTP ${status}`, fix: 'Return 200 or remove it.' }] };
|
|
110
|
+
let doc;
|
|
111
|
+
try { doc = JSON.parse(text); } catch { return { present: true, findings: [{ severity: 'error', message: '/.well-known/acp.json is not valid JSON', fix: 'Fix the JSON.' }] }; }
|
|
112
|
+
if (doc?.protocol?.name !== 'acp') findings.push({ severity: 'error', message: 'protocol.name must be "acp"', fix: 'Set protocol.name to "acp".' });
|
|
113
|
+
if (!doc?.protocol?.version) findings.push({ severity: 'warning', message: 'protocol.version is missing', fix: 'Add the ACP spec version.' });
|
|
114
|
+
if (!doc?.api_base_url || !isHttpsUrl(doc.api_base_url)) findings.push({ severity: 'error', message: 'api_base_url is missing or not https', fix: 'Point api_base_url at your https ACP API base.' });
|
|
115
|
+
return { present: true, findings, doc };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const SHOPPING_BOTS = [
|
|
119
|
+
{ token: 'OAI-SearchBot', who: 'ChatGPT search and shopping' },
|
|
120
|
+
{ token: 'ChatGPT-User', who: 'ChatGPT browsing' },
|
|
121
|
+
{ token: 'Googlebot', who: 'Google Search, AI Mode and Shopping' },
|
|
122
|
+
{ token: 'Bingbot', who: 'Bing and Copilot shopping' },
|
|
123
|
+
{ token: 'PerplexityBot', who: 'Perplexity shopping' },
|
|
124
|
+
{ token: 'Claude-SearchBot', who: 'Claude search' },
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
export async function checkDiscovery(origin, { productPath = '/', timeoutMs } = {}) {
|
|
128
|
+
const out = { ucp: null, acp: null, agentCard: false, robots: [] };
|
|
129
|
+
try {
|
|
130
|
+
const r = await get(`${origin}/.well-known/ucp`, { timeoutMs, redirect: 'manual' });
|
|
131
|
+
out.ucp = validateUcpProfile({ ...r, url: `${origin}/.well-known/ucp` });
|
|
132
|
+
} catch (e) { out.ucp = { present: false, error: e.message, findings: [] }; }
|
|
133
|
+
try {
|
|
134
|
+
const r = await get(`${origin}/.well-known/acp.json`, { timeoutMs, redirect: 'manual' });
|
|
135
|
+
out.acp = validateAcpDiscovery(r);
|
|
136
|
+
} catch (e) { out.acp = { present: false, error: e.message, findings: [] }; }
|
|
137
|
+
try {
|
|
138
|
+
const r = await get(`${origin}/.well-known/agent-card.json`, { timeoutMs });
|
|
139
|
+
out.agentCard = r.status === 200 && /^\s*\{/.test(r.text);
|
|
140
|
+
} catch { /* ignore */ }
|
|
141
|
+
try {
|
|
142
|
+
const r = await get(`${origin}/robots.txt`, { timeoutMs });
|
|
143
|
+
if (r.status === 200 && !/<html/i.test(r.text.slice(0, 300))) {
|
|
144
|
+
const parsed = parseRobots(r.text);
|
|
145
|
+
for (const b of SHOPPING_BOTS) out.robots.push({ ...b, allowed: isAllowed(parsed, b.token, productPath) });
|
|
146
|
+
}
|
|
147
|
+
} catch { /* ignore */ }
|
|
148
|
+
return out;
|
|
149
|
+
}
|
package/src/live/http.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const USER_AGENT = 'agentic-commerce-readiness/0.1 (+https://www.ahmadzia.com/tools/agentic-commerce-readiness)';
|
|
2
|
+
|
|
3
|
+
/** GET with timeout. redirect: 'manual' lets callers detect 3xx (UCP forbids redirects). */
|
|
4
|
+
export async function get(url, { timeoutMs = 15000, redirect = 'follow', headers = {}, maxBytes = 8_000_000 } = {}) {
|
|
5
|
+
const res = await fetch(url, { headers: { 'user-agent': USER_AGENT, accept: 'application/json,text/html;q=0.9,*/*;q=0.8', ...headers }, redirect, signal: AbortSignal.timeout(timeoutMs) });
|
|
6
|
+
let text = '';
|
|
7
|
+
if (res.body) {
|
|
8
|
+
const reader = res.body.getReader();
|
|
9
|
+
const chunks = [];
|
|
10
|
+
let total = 0;
|
|
11
|
+
while (true) {
|
|
12
|
+
const { done, value } = await reader.read();
|
|
13
|
+
if (done) break;
|
|
14
|
+
total += value.length;
|
|
15
|
+
if (total > maxBytes) { await reader.cancel(); break; }
|
|
16
|
+
chunks.push(Buffer.from(value));
|
|
17
|
+
}
|
|
18
|
+
text = Buffer.concat(chunks).toString('utf8');
|
|
19
|
+
}
|
|
20
|
+
return { status: res.status, headers: res.headers, text, url: res.url || url, redirected: res.redirected };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function getJson(url, opts) {
|
|
24
|
+
const r = await get(url, opts);
|
|
25
|
+
let json = null;
|
|
26
|
+
try { json = JSON.parse(r.text); } catch { /* not json */ }
|
|
27
|
+
return { ...r, json };
|
|
28
|
+
}
|
package/src/report.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { groupIssues } from './feed/validate.js';
|
|
2
|
+
|
|
3
|
+
const CH_SHORT = { chatgpt: 'ChatGPT', google: 'Google' };
|
|
4
|
+
const CH = { chatgpt: 'ChatGPT shopping', google: 'Google AI Mode / Gemini / Shopping', agents: 'Other AI agents (UCP, crawlers)' };
|
|
5
|
+
const COVER = {
|
|
6
|
+
gtin_or_mpn: 'GTIN or MPN', product_category: 'Product category', rich_description: 'Description 300+ characters',
|
|
7
|
+
additional_images: '2+ extra images', color_or_size_or_material: 'Color, size or material', returns: 'Return info',
|
|
8
|
+
shipping: 'Shipping cost', reviews: 'Reviews',
|
|
9
|
+
};
|
|
10
|
+
const bar = (n) => '█'.repeat(Math.round(n / 10)) + '░'.repeat(10 - Math.round(n / 10));
|
|
11
|
+
|
|
12
|
+
export function formatText(r, { maxGroups = 25 } = {}) {
|
|
13
|
+
const out = [''];
|
|
14
|
+
out.push(`Agentic commerce readiness: ${r.target}`);
|
|
15
|
+
out.push(r.mode === 'store' ? `Platform: ${r.platform} Items checked: ${r.records.length}${r.currency ? ` Currency: ${r.currency}` : ''}` : `Feed format: ${r.format} Items: ${r.records.length}`);
|
|
16
|
+
out.push('');
|
|
17
|
+
out.push('Readiness by channel');
|
|
18
|
+
for (const [ch, v] of Object.entries(r.readiness)) {
|
|
19
|
+
out.push(` ${CH[ch].padEnd(38)} ${bar(v.score)} ${String(v.score).padStart(3)}/100`);
|
|
20
|
+
for (const p of v.parts) out.push(` ${p.name.padEnd(44)} ${String(p.value).padStart(3)}%`);
|
|
21
|
+
}
|
|
22
|
+
out.push('');
|
|
23
|
+
for (const [ch, s] of Object.entries(r.stats.perChannel)) out.push(` ${CH[ch]}: ${s.eligible} of ${s.total} items have no blocking errors (${s.eligiblePct}%)`);
|
|
24
|
+
out.push('');
|
|
25
|
+
|
|
26
|
+
if (r.parseErrors?.length) {
|
|
27
|
+
out.push(`Lines that could not be read (${r.parseErrors.length})`);
|
|
28
|
+
for (const e of r.parseErrors.slice(0, 5)) out.push(` [ERROR] ${e.message}`);
|
|
29
|
+
out.push('');
|
|
30
|
+
}
|
|
31
|
+
const groups = groupIssues(r.issues);
|
|
32
|
+
if (groups.length) {
|
|
33
|
+
out.push('Issues (most important first)');
|
|
34
|
+
for (const g of groups.slice(0, maxGroups)) {
|
|
35
|
+
const tag = g.severity === 'error' ? '[ERROR] ' : g.severity === 'warning' ? '[WARNING]' : '[TIP] ';
|
|
36
|
+
out.push(` ${tag} ${g.channels.map((c) => CH_SHORT[c]).join(' + ')} · ${g.count} item(s) · ${g.code}`);
|
|
37
|
+
if (g.uniform) {
|
|
38
|
+
out.push(` ${g.message}`);
|
|
39
|
+
if (g.itemIds.some((x) => x !== '(feed)')) out.push(` items: ${g.itemIds.join(', ')}${g.count > g.itemIds.length ? ` and ${g.count - g.itemIds.length} more` : ''}`);
|
|
40
|
+
out.push(` fix: ${g.fix}`);
|
|
41
|
+
} else {
|
|
42
|
+
for (const e of g.examples) {
|
|
43
|
+
out.push(` ${e.item_id ? String(e.item_id).padEnd(14) + ' ' : ''}${e.message}`);
|
|
44
|
+
out.push(` ${' '.repeat(e.item_id ? 15 : 0)}fix: ${e.fix}`);
|
|
45
|
+
}
|
|
46
|
+
if (g.count > g.examples.length) out.push(` ...and ${g.count - g.examples.length} more`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (groups.length > maxGroups) out.push(` ... and ${groups.length - maxGroups} more issue types (use --md or --json for the full list)`);
|
|
50
|
+
out.push('');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (r.mode === 'store') {
|
|
54
|
+
const d = r.discovery;
|
|
55
|
+
out.push('Discovery');
|
|
56
|
+
out.push(` /.well-known/ucp ${d.ucp?.present ? (d.ucp.valid ? 'valid' : 'present, with errors') : 'not published (agentic checkout in Google AI Mode and Gemini uses it; publish only with working UCP endpoints)'}`);
|
|
57
|
+
for (const f of d.ucp?.findings || []) out.push(` [${f.severity}] ${f.message} -> ${f.fix}`);
|
|
58
|
+
out.push(` /.well-known/acp.json ${d.acp?.present ? 'present' : 'not published (optional; ChatGPT discovery uses your product feed)'}`);
|
|
59
|
+
for (const f of d.acp?.findings || []) out.push(` [${f.severity}] ${f.message} -> ${f.fix}`);
|
|
60
|
+
if (d.robots.length) {
|
|
61
|
+
out.push(' Shopping crawlers (robots.txt, product pages):');
|
|
62
|
+
for (const b of d.robots) out.push(` ${b.allowed ? 'allowed' : 'BLOCKED'} ${b.token.padEnd(17)} ${b.who}`);
|
|
63
|
+
const blocked = d.robots.filter((b) => !b.allowed);
|
|
64
|
+
if (blocked.length) {
|
|
65
|
+
out.push(' fix: if you want these assistants to show your products, add to robots.txt:');
|
|
66
|
+
for (const b of blocked) out.push(` User-agent: ${b.token}`, ' Allow: /');
|
|
67
|
+
}
|
|
68
|
+
} else out.push(' robots.txt not found or unreadable (crawlers assume everything is allowed)');
|
|
69
|
+
out.push('');
|
|
70
|
+
if (r.consistency.length) {
|
|
71
|
+
const bad = r.consistency.filter((c) => c.findings.some((f) => f.severity === 'error'));
|
|
72
|
+
out.push(`Feed vs product page (${r.consistency.length} pages sampled, ${bad.length} with mismatches)`);
|
|
73
|
+
for (const c of r.consistency) {
|
|
74
|
+
for (const f of c.findings) {
|
|
75
|
+
if (f.severity === 'tip') continue;
|
|
76
|
+
out.push(` [${f.severity}] ${c.item_id}: ${f.message}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const fixes = new Map();
|
|
80
|
+
for (const c of r.consistency) for (const f of c.findings) if (f.severity !== 'tip' && f.fix && !fixes.has(f.code)) fixes.set(f.code, f.fix);
|
|
81
|
+
if (fixes.size) {
|
|
82
|
+
out.push(' How to fix:');
|
|
83
|
+
for (const [code, fix] of fixes) out.push(` ${code}: ${fix}`);
|
|
84
|
+
}
|
|
85
|
+
out.push('');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
out.push('Attribute coverage (what AI agents match on)');
|
|
90
|
+
for (const [k, v] of Object.entries(r.stats.coverage)) out.push(` ${COVER[k].padEnd(30)} ${bar(v)} ${String(v).padStart(3)}%`);
|
|
91
|
+
out.push('');
|
|
92
|
+
if (r.notes?.length) {
|
|
93
|
+
out.push('Notes');
|
|
94
|
+
for (const n of r.notes) out.push(` - ${n}`);
|
|
95
|
+
out.push('');
|
|
96
|
+
}
|
|
97
|
+
out.push('Specs: OpenAI product feed schema, Google Merchant Center product data spec, UCP specification.');
|
|
98
|
+
out.push('Help with agentic commerce: https://www.ahmadzia.com/tools/agentic-commerce-readiness');
|
|
99
|
+
return out.join('\n');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function formatMarkdown(r) {
|
|
103
|
+
const esc = (s) => String(s ?? '').replace(/\|/g, '\\|').replace(/\n/g, ' ');
|
|
104
|
+
const out = [`# Agentic commerce readiness: ${r.target}`, ''];
|
|
105
|
+
out.push('| Channel | Score | Items without blocking errors |', '|---|---|---|');
|
|
106
|
+
for (const [ch, v] of Object.entries(r.readiness)) {
|
|
107
|
+
const s = r.stats.perChannel[ch];
|
|
108
|
+
out.push(`| ${CH[ch]} | ${v.score}/100 | ${s ? `${s.eligible} of ${s.total} (${s.eligiblePct}%)` : '-'} |`);
|
|
109
|
+
}
|
|
110
|
+
out.push('', '## Issues', '', '| Severity | Channels | Items | Example | Fix |', '|---|---|---|---|---|');
|
|
111
|
+
for (const g of groupIssues(r.issues)) out.push(`| ${g.severity} | ${g.channels.map((c) => CH_SHORT[c]).join(', ')} | ${g.count} | ${esc((g.examples[0].item_id ? g.examples[0].item_id + ': ' : '') + g.examples[0].message)} | ${esc(g.examples[0].fix)} |`);
|
|
112
|
+
if (r.parseErrors?.length) out.push('', '## Unreadable lines', ...r.parseErrors.map((e) => `- ${esc(e.message)}`));
|
|
113
|
+
if (r.mode === 'store') {
|
|
114
|
+
out.push('', '## Discovery', '');
|
|
115
|
+
out.push(`- UCP profile: ${r.discovery.ucp?.present ? (r.discovery.ucp.valid ? 'valid' : 'present, with errors') : 'not published'}`);
|
|
116
|
+
for (const f of r.discovery.ucp?.findings || []) out.push(` - ${f.severity}: ${esc(f.message)}`);
|
|
117
|
+
out.push(`- ACP discovery: ${r.discovery.acp?.present ? 'present' : 'not published (optional)'}`);
|
|
118
|
+
for (const b of r.discovery.robots) out.push(`- ${b.token}: ${b.allowed ? 'allowed' : 'blocked'}`);
|
|
119
|
+
if (r.consistency.length) {
|
|
120
|
+
out.push('', '## Feed vs product page', '', '| Item | Finding |', '|---|---|');
|
|
121
|
+
for (const c of r.consistency) for (const f of c.findings) out.push(`| ${esc(c.item_id)} | ${f.severity}: ${esc(f.message)}${f.fix ? ` Fix: ${esc(f.fix)}` : ''} |`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
out.push('', '## Attribute coverage', '', '| Attribute | Items |', '|---|---|');
|
|
125
|
+
for (const [k, v] of Object.entries(r.stats.coverage)) out.push(`| ${COVER[k]} | ${v}% |`);
|
|
126
|
+
if (r.notes?.length) out.push('', '## Notes', ...r.notes.map((n) => `- ${n}`));
|
|
127
|
+
return out.join('\n') + '\n';
|
|
128
|
+
}
|