agentface 0.10.0 → 0.11.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.
Files changed (2) hide show
  1. package/dist/agentface.mjs +715 -653
  2. package/package.json +1 -1
@@ -45159,6 +45159,7 @@ var import_parser = __toESM(require_lib(), 1);
45159
45159
  import { execFile as execFile2 } from "node:child_process";
45160
45160
  import { readdir, readFile as readFile2, stat as stat2 } from "node:fs/promises";
45161
45161
  import path2 from "node:path";
45162
+ import { deflateRawSync } from "node:zlib";
45162
45163
 
45163
45164
  // worker/head.ts
45164
45165
  var ATTRIBUTES = String.raw`(?:\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}|"[^"]*"|'[^']*'|[^>"'{/]|\/(?!>))*`;
@@ -45175,7 +45176,7 @@ function headEnd(html) {
45175
45176
  // cli/package.json
45176
45177
  var package_default = {
45177
45178
  name: "agentface",
45178
- version: "0.10.0",
45179
+ version: "0.11.0",
45179
45180
  description: "Add the Agentface tag to a website's pages, so AI agents get tools made for it, and use your agentface account from a shell.",
45180
45181
  repository: {
45181
45182
  type: "git",
@@ -45195,235 +45196,8 @@ var package_default = {
45195
45196
  license: "UNLICENSED"
45196
45197
  };
45197
45198
 
45198
- // cli/zip.mts
45199
- import { deflateRawSync } from "node:zlib";
45200
- var CRC_TABLE = Array.from({ length: 256 }, (_, n) => {
45201
- let c = n;
45202
- for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
45203
- return c >>> 0;
45204
- });
45205
- function crc32(data) {
45206
- let c = 4294967295;
45207
- for (const byte of data) c = CRC_TABLE[(c ^ byte) & 255] ^ c >>> 8;
45208
- return (c ^ 4294967295) >>> 0;
45209
- }
45210
- function zip(files2, date = /* @__PURE__ */ new Date()) {
45211
- const time = date.getHours() << 11 | date.getMinutes() << 5 | date.getSeconds() >> 1;
45212
- const day = date.getFullYear() - 1980 << 9 | date.getMonth() + 1 << 5 | date.getDate();
45213
- const parts = [];
45214
- const directory = [];
45215
- let offset = 0;
45216
- for (const [name, text2] of Object.entries(files2)) {
45217
- const data = Buffer.from(text2);
45218
- const packed = deflateRawSync(data);
45219
- const path6 = Buffer.from(name);
45220
- const shared = Buffer.alloc(26);
45221
- shared.writeUInt16LE(20, 0);
45222
- shared.writeUInt16LE(2048, 2);
45223
- shared.writeUInt16LE(8, 4);
45224
- shared.writeUInt16LE(time, 6);
45225
- shared.writeUInt16LE(day, 8);
45226
- shared.writeUInt32LE(crc32(data), 10);
45227
- shared.writeUInt32LE(packed.length, 14);
45228
- shared.writeUInt32LE(data.length, 18);
45229
- shared.writeUInt16LE(path6.length, 22);
45230
- const local = Buffer.alloc(4);
45231
- local.writeUInt32LE(67324752);
45232
- parts.push(local, shared, path6, packed);
45233
- const entry2 = Buffer.alloc(46);
45234
- entry2.writeUInt32LE(33639248, 0);
45235
- entry2.writeUInt16LE(788, 4);
45236
- shared.copy(entry2, 6);
45237
- entry2.writeUInt32LE(33188 * 65536, 38);
45238
- entry2.writeUInt32LE(offset, 42);
45239
- directory.push(entry2, path6);
45240
- offset += 4 + shared.length + path6.length + packed.length;
45241
- }
45242
- const size = directory.reduce((total, part) => total + part.length, 0);
45243
- const end = Buffer.alloc(22);
45244
- end.writeUInt32LE(101010256, 0);
45245
- end.writeUInt16LE(Object.keys(files2).length, 8);
45246
- end.writeUInt16LE(Object.keys(files2).length, 10);
45247
- end.writeUInt32LE(size, 12);
45248
- end.writeUInt32LE(offset, 16);
45249
- return Buffer.concat([...parts, ...directory, end]);
45250
- }
45251
-
45252
- // cli/heads.mts
45199
+ // cli/ours.mts
45253
45200
  var INIT = package_default.version;
45254
- var stamped = (tag) => tag.replace(/><\/script>$/, ` data-init="${INIT}"></script>`);
45255
- var EXTENSIONS = [
45256
- "html",
45257
- "htm",
45258
- "php",
45259
- "njk",
45260
- "liquid",
45261
- "hbs",
45262
- "handlebars",
45263
- "mustache",
45264
- "ejs",
45265
- "erb",
45266
- "twig",
45267
- "jinja",
45268
- "jinja2",
45269
- "j2",
45270
- "tmpl",
45271
- "tpl",
45272
- "astro",
45273
- "heex"
45274
- ];
45275
- var MARKUP = new RegExp(`\\.(?:${EXTENSIONS.join("|")})$`, "i");
45276
- var COMPONENT = /\.(?:[cm]?[jt]sx?|vue|svelte|mdx)$/i;
45277
- var LAYOUTS = [
45278
- /(?:^|\/)app\/(?:.+\/)?layout\.[cm]?[jt]sx?$/,
45279
- /(?:^|\/)pages\/_document\.[cm]?[jt]sx?$/,
45280
- /(?:^|\/)app\/root\.[cm]?[jt]sx?$/,
45281
- /(?:^|\/)routes\/__root\.[cm]?[jt]sx?$/,
45282
- /(?:^|\/)src\/html\.[cm]?[jt]sx?$/
45283
- ];
45284
- var SKIP = /* @__PURE__ */ new Set([
45285
- "node_modules",
45286
- "bower_components",
45287
- "vendor",
45288
- "dist",
45289
- "build",
45290
- "out",
45291
- "_site",
45292
- "coverage",
45293
- "tmp",
45294
- "temp",
45295
- "test",
45296
- "tests",
45297
- "__tests__",
45298
- "__mocks__",
45299
- "fixtures",
45300
- "__fixtures__",
45301
- "e2e",
45302
- "cypress",
45303
- "playwright",
45304
- "storybook-static",
45305
- "wp-admin",
45306
- "wp-includes",
45307
- // A Python environment's packages, and Elixir's builds.
45308
- "site-packages",
45309
- "dist-packages",
45310
- "__pycache__",
45311
- "_build"
45312
- ]);
45313
- var MAIL = /mail/i;
45314
- var PRINTED = /(?:^|[-_.])(?:pdfs?|invoices?|receipts?|print(?:able)?)(?=$|[-_.])/i;
45315
- var notMail = (name) => !MAIL.test(name) && !PRINTED.test(name);
45316
- var AMP = /<html\b[^>]*\s(?:amp|⚡)[\s>=/]/i;
45317
- var CODE = /<\?(?!xml\b)[\s\S]*?(?:\?>|$)|<%[\s\S]*?(?:%>|$)/g;
45318
- function inCode(source, at) {
45319
- for (const code of source.matchAll(CODE)) {
45320
- if (code.index > at) return false;
45321
- if (at < code.index + code[0].length) return true;
45322
- }
45323
- return false;
45324
- }
45325
- var MAX_FILES = 2e4;
45326
- var MAX_BYTES = 1e6;
45327
- var CONFIG_HEAD = {
45328
- nuxt: ["Nuxt", "`app.head.script` in nuxt.config"],
45329
- "@docusaurus/core": ["Docusaurus", "`scripts` in docusaurus.config"],
45330
- vitepress: ["VitePress", "`head` in .vitepress/config"]
45331
- };
45332
- var FRAMEWORKS = [
45333
- ["next", "Next.js"],
45334
- ["@tanstack/react-start", "TanStack Start"],
45335
- ["@react-router/dev", "React Router"],
45336
- ["@remix-run/dev", "Remix"],
45337
- ["gatsby", "Gatsby"],
45338
- ["@sveltejs/kit", "SvelteKit"],
45339
- ["astro", "Astro"],
45340
- ["@11ty/eleventy", "Eleventy"],
45341
- ["@angular/core", "Angular"],
45342
- ["react-scripts", "Create React App"],
45343
- ["@vue/cli-service", "Vue CLI"],
45344
- ["vite", "Vite"]
45345
- ];
45346
- var read = (file) => readFile2(file, "utf8").catch(() => null);
45347
- var exists = (file) => stat2(file).then(
45348
- () => true,
45349
- () => false
45350
- );
45351
- var THEME = /^(?:[ \t]*<\?php)?[ \t/*#@]*Theme Name\s*:/im;
45352
- async function isWordPress(dir) {
45353
- if (THEME.test((await read(path2.join(dir, "style.css")) ?? "").slice(0, 8192))) return true;
45354
- for (const name of ["wp-content", "wp-includes"]) if (await exists(path2.join(dir, name))) return true;
45355
- for (let at = path2.resolve(dir); ; at = path2.dirname(at)) {
45356
- if (path2.basename(at) === "wp-content" || await exists(path2.join(at, "wp-config.php"))) return true;
45357
- if (path2.dirname(at) === at) return false;
45358
- }
45359
- }
45360
- async function contentFolder(dir) {
45361
- const here = path2.resolve(dir);
45362
- for (let at = here; ; at = path2.dirname(at)) {
45363
- if (path2.basename(at) === "wp-content") return at;
45364
- const content = path2.join(at, "wp-content");
45365
- if ((at === here || await exists(path2.join(at, "wp-config.php"))) && await exists(content))
45366
- return content;
45367
- if (path2.dirname(at) === at) return null;
45368
- }
45369
- }
45370
- async function wordPressFile(dir) {
45371
- const content = await contentFolder(dir);
45372
- return content && path2.relative(dir, path2.join(content, "mu-plugins", "agentface.php")).split(path2.sep).join("/");
45373
- }
45374
- var wordPressPage = (html) => /\/wp-(?:content|includes)\/|["']https:\/\/api\.w\.org\/["']|<meta\b[^>]*\bcontent=["']WordPress\b/i.test(
45375
- html
45376
- );
45377
- var WORDPRESS_STEPS = (tag, notice) => [
45378
- 'In the WordPress admin, open Plugins > Add New Plugin, search for WPCode, then install and activate "WPCode \u2013 Insert Headers and Footers".',
45379
- "Open Code Snippets > Header & Footer.",
45380
- `Paste this line in the Header box. If the box has an Agentface line from an earlier run, replace that line with it:
45381
-
45382
- ${tag}`,
45383
- ...notice ? [
45384
- `Paste this line in the Body box. If the box has an Agentface line from an earlier run, replace that line with it:
45385
-
45386
- ${notice}`
45387
- ] : [],
45388
- "Click Save Changes. If the site has a caching plugin, clear its cache, so the homepage shows the change."
45389
- ].map((step, i) => ` ${i + 1}. ${step}`).join("\n\n") + "\n";
45390
- var wordPressManual = (lead) => ({
45391
- reason: `${lead} Run in the site's folder, the one with wp-config.php, init adds a plugin of its own that puts the tag on every page. It never edits WordPress's, its plugins' or its theme's files: updates put them back and take the tag away, and a header plugin or page builder, such as Elementor's, can replace the theme's header, so that a tag put there reaches no page.`,
45392
- how: "Or add it with a plugin that has boxes for the site's head and body, such as the free WPCode",
45393
- steps: WORDPRESS_STEPS
45394
- });
45395
- var SHOP = /\b_PS_[A-Z_]+_\b/;
45396
- var PRESTASHOP_MODULE_FILE = "agentface/agentface.php";
45397
- async function shopFolder(dir) {
45398
- for (let at = path2.resolve(dir); ; at = path2.dirname(at)) {
45399
- if (SHOP.test(await read(path2.join(at, "config", "defines.inc.php")) ?? "")) return at;
45400
- if (path2.dirname(at) === at) return null;
45401
- }
45402
- }
45403
- async function prestaShopFile(dir) {
45404
- const shop = await shopFolder(dir);
45405
- return shop && path2.relative(dir, path2.join(shop, "modules", PRESTASHOP_MODULE_FILE)).split(path2.sep).join("/");
45406
- }
45407
- async function prestaShopTheme(dir) {
45408
- return /^name\s*:/m.test(await read(path2.join(dir, "config", "theme.yml")) ?? "") && await exists(path2.join(dir, "templates"));
45409
- }
45410
- var prestaShopPage = (html) => /\bvar\s+prestashop\s*=/.test(html);
45411
- var KEY = /\/s\/(site-[a-z0-9-]+)\.js(?=[?#"'`\s]|$)/;
45412
- var BRACES = String.raw`\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}`;
45413
- var ATTRIBUTES2 = `(?:${BRACES}|[^>])*?`;
45414
- var TAG = new RegExp(
45415
- `<script\\b${ATTRIBUTES2}${KEY.source}${ATTRIBUTES2}(?:\\/>|>\\s*<\\/script\\s*>)`,
45416
- "gi"
45417
- );
45418
- var ATTRIBUTE = new RegExp(
45419
- `(${BRACES})|([^\\s"'<>/={}]+)(?:\\s*=\\s*(${BRACES}|"[^"]*"|'[^']*'|[^\\s"'<>=]+))?`,
45420
- "g"
45421
- );
45422
- var NOTICE = /<noscript\b[^>]*>[^<]*\/s\/(site-[a-z0-9-]+)\.md[^<]*<\/noscript\s*>/i;
45423
- var MADE_NOTICE = /createElement\(\s*['"]noscript['"][^()]*\/s\/(site-[a-z0-9-]+)\.md/;
45424
- var LIST = /\/s\/(site-[a-z0-9-]+)\.md(?![\w-])/;
45425
- var BODY = /<body(?=[\s>/])(?:<\?[\s\S]*?\?>|<%[\s\S]*?%>|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}|"[^"]*"|'[^']*'|[^>])*>/i;
45426
- var onItsLine = (pattern) => new RegExp(`(\\r?\\n[ \\t]*)?${pattern.source}`, "gi");
45427
45201
  var OURS = "Added by `npx agentface init`";
45428
45202
  var about = (comment2, how) => [
45429
45203
  `${OURS}. It asks Agentface for the two lines this`,
@@ -45433,224 +45207,12 @@ var about = (comment2, how) => [
45433
45207
  how,
45434
45208
  "`npx agentface uninstall` deletes it."
45435
45209
  ].join("\n").replace(/^/gm, comment2 + " ").replace(/ +$/gm, "");
45436
- function tagKey(source) {
45437
- return source.match(KEY)?.[1] ?? null;
45438
- }
45439
- function noticeKey(source) {
45440
- return source.match(NOTICE)?.[1] ?? null;
45441
- }
45442
45210
  function siteOf(tag) {
45443
45211
  const [, service = "", site = ""] = tag.match(/\bsrc="(https?:\/\/[^"]+?)\/s\/([^/"]+)\.js"/) ?? [];
45444
45212
  return { service, site };
45445
45213
  }
45446
- var linesIn = (source) => ({
45447
- tag: source.match(TAG)?.[0] ?? null,
45448
- notice: source.match(NOTICE)?.[0] ?? null
45449
- });
45450
- var squash = (text2) => text2.replace(/\s+/g, " ").trim();
45451
- var said2 = (value = "") => squash(value.replace(/^\{\s*(["'`][\s\S]*["'`])\s*\}$/, "$1").replace(/^(["'`])([\s\S]*)\1$/, "$2"));
45452
- function attributesOf(tag) {
45453
- const inside = tag.replace(/^<script\b/i, "").replace(/(?:\/>|>\s*<\/script\s*>)$/i, "");
45454
- return [...inside.matchAll(ATTRIBUTE)].map(
45455
- ([, braces, name, value]) => braces ? { name: null, value: void 0, text: braces } : { name: name.toLowerCase(), value, text: value === void 0 ? name : `${name}=${value}` }
45456
- );
45457
- }
45458
- function updatedTag(old, tag) {
45459
- const now = attributesOf(tag);
45460
- const was = attributesOf(old);
45461
- const mine = initsOwn(was, now);
45462
- const init2 = (list2) => list2.some(({ name }) => name === "data-init");
45463
- const rest = (list2) => list2.filter(({ name }) => name !== "data-init");
45464
- const current2 = rest(mine).length === rest(now).length && (init2(mine) || !init2(now)) && rest(now).every(({ name, value }) => {
45465
- const same = mine.find((attribute2) => attribute2.name === name);
45466
- return same && (value === void 0 || said2(same.value) === said2(value));
45467
- });
45468
- if (current2) return old;
45469
- const kept = was.filter((attribute2) => !mine.includes(attribute2)).map(({ text: text2 }) => text2);
45470
- return kept.length ? tag.replace(/^<script\b/, () => `<script ${kept.join(" ")}`) : tag;
45471
- }
45472
- function initsOwn(was, now) {
45473
- const names = /* @__PURE__ */ new Set(["src", "async", "defer", "data-init", ...now.map(({ name }) => name)]);
45474
- return was.filter(({ name, value }) => name !== null && (names.has(name) || LIST.test(value ?? "")));
45475
- }
45476
- function ownersAttributes(old) {
45477
- const was = attributesOf(old);
45478
- const mine = initsOwn(was, []);
45479
- return was.filter((attribute2) => !mine.includes(attribute2)).map(({ text: text2 }) => text2);
45480
- }
45481
- function updatedNotice(old, notice) {
45482
- const parts = (line) => line.match(/^<noscript\b([^>]*)>([^<]*)<\/noscript\s*>$/i) ?? [];
45483
- const [, attributes = "", text2 = ""] = parts(old);
45484
- if (squash(text2) === squash(parts(notice)[2] ?? "")) return old;
45485
- return squash(attributes) ? notice.replace(/^<noscript\b/, () => `<noscript ${squash(attributes)}`) : notice;
45486
- }
45487
- function tagToReplace(source, tag) {
45488
- const old = source.match(TAG)?.[0];
45489
- const next2 = old && updatedTag(old, tag.replace(/\sdata-init="[^"]*"/, ""));
45490
- return next2 && next2 !== old ? updatedTag(old, tag) : null;
45491
- }
45492
- function staleNotice(source, notice) {
45493
- const key = noticeKey(notice);
45494
- return [...source.matchAll(new RegExp(NOTICE.source, "gi"))].some(
45495
- ([old, its]) => its === key && updatedNotice(old, notice) !== old
45496
- );
45497
- }
45498
- function oldWords(source, words, key) {
45499
- const rest = source.replace(TAG, "").replace(new RegExp(NOTICE.source, "gi"), "");
45500
- for (const match of rest.matchAll(new RegExp(LIST.source, "g"))) {
45501
- if (match[1] !== key) continue;
45502
- const before = rest.slice(Math.max(0, match.index - 400), match.index);
45503
- const written = before.match(/([^"'`<>{}]*?)\s*https?:\/\/[^\s"'`<>{}]*$/)?.[1];
45504
- if (written && squash(written) && squash(written) !== squash(words)) return true;
45505
- }
45506
- return false;
45507
- }
45508
- function indentUnit(source) {
45509
- return source.match(/^(\t| {2,4})\S/m)?.[1] ?? " ";
45510
- }
45511
- var indentOf = (line) => line.match(/^[ \t]*/)[0];
45512
- function addTag(source, tag) {
45513
- let first = true;
45514
- const replaced = source.replace(onItsLine(TAG), (match, line) => {
45515
- if (!first) return "";
45516
- first = false;
45517
- return (line ?? "") + updatedTag(match.slice(line?.length ?? 0), tag);
45518
- });
45519
- if (!first) return replaced;
45520
- const eol = source.includes("\r\n") ? "\r\n" : "\n";
45521
- const at = headEnd(source);
45522
- const close = at !== -1 && /^<\/head\s*>/i.test(source.slice(at)) ? at : -1;
45523
- if (close !== -1) {
45524
- const lineStart = source.lastIndexOf("\n", close - 1) + 1;
45525
- const before = source.slice(lineStart, close);
45526
- if (!/^[ \t]*$/.test(before)) return source.slice(0, close) + tag + source.slice(close);
45527
- const previous = source.slice(0, lineStart).split(/\r?\n/).findLast((line) => line.trim());
45528
- const sibling = indentOf(previous ?? "");
45529
- const indent = previous && !/<head\b[^>]*>\s*$/i.test(previous) && sibling.startsWith(before) ? sibling : before + indentUnit(source);
45530
- return source.slice(0, lineStart) + indent + tag + eol + source.slice(lineStart);
45531
- }
45532
- const html = /<html\b[^>]*>/.exec(source);
45533
- if (!html) return null;
45534
- const end = html.index + html[0].length;
45535
- const child = source.slice(end).match(/^\r?\n([ \t]*)\S/)?.[1];
45536
- if (child === void 0) return source.slice(0, end) + `<head>${tag}</head>` + source.slice(end);
45537
- const outer = indentOf(source.slice(source.lastIndexOf("\n", html.index) + 1));
45538
- const step = child.length > outer.length && child.startsWith(outer) ? child.slice(outer.length) : indentUnit(source);
45539
- const lines = [`${child}<head>`, `${child}${step}${tag}`, `${child}</head>`];
45540
- return source.slice(0, end) + eol + lines.join(eol) + source.slice(end);
45541
- }
45542
- function addNotice(source, notice) {
45543
- let first = true;
45544
- const replaced = source.replace(onItsLine(NOTICE), (match, line) => {
45545
- if (!first) return "";
45546
- first = false;
45547
- return (line ?? "") + updatedNotice(match.slice(line?.length ?? 0), notice);
45548
- });
45549
- if (!first) return replaced;
45550
- const body = BODY.exec(source);
45551
- if (!body) return null;
45552
- const end = body.index + body[0].length;
45553
- const next2 = source.slice(end).match(/^[ \t]*\r?\n([ \t]*)(.*)/);
45554
- if (!next2) return source.slice(0, end) + notice + source.slice(end);
45555
- const eol = source.includes("\r\n") ? "\r\n" : "\n";
45556
- const outer = indentOf(source.slice(source.lastIndexOf("\n", body.index) + 1));
45557
- const indent = next2[2].trim() && !/^<\/body\b/i.test(next2[2]) ? next2[1] : outer + indentUnit(source);
45558
- return source.slice(0, end) + eol + indent + notice + source.slice(end);
45559
- }
45560
- function gitFiles(dir) {
45561
- return new Promise((resolve2) => {
45562
- execFile2(
45563
- "git",
45564
- ["ls-files", "--cached", "--others", "--exclude-standard", "-z"],
45565
- { cwd: dir, maxBuffer: 64 * 1024 * 1024 },
45566
- (error, stdout) => resolve2(error ? null : [...new Set(stdout.split("\0").filter(Boolean))].sort())
45567
- );
45568
- });
45569
- }
45570
- async function files(dir, skip) {
45571
- const kept = (name) => (!name.startsWith(".") || name === ".vitepress") && !skip.has(name) && notMail(name);
45572
- const tracked = await gitFiles(dir);
45573
- if (tracked)
45574
- return {
45575
- git: true,
45576
- files: tracked.filter((file) => file.split("/").slice(0, -1).every(kept)).slice(0, MAX_FILES)
45577
- };
45578
- const found = [];
45579
- const visit = async (rel) => {
45580
- const entries = await readdir(path2.join(dir, rel), { withFileTypes: true }).catch(() => []);
45581
- for (const entry2 of entries.sort((a, b) => a.name.localeCompare(b.name))) {
45582
- const file = rel ? `${rel}/${entry2.name}` : entry2.name;
45583
- if (entry2.isDirectory()) {
45584
- if (kept(entry2.name)) await visit(file);
45585
- } else if (entry2.isFile() && found.length < MAX_FILES) found.push(file);
45586
- }
45587
- };
45588
- await visit("");
45589
- return { git: false, files: found };
45590
- }
45591
- async function contents(dir, file) {
45592
- const info = await stat2(path2.join(dir, file)).catch(() => null);
45593
- return info?.isFile() && info.size <= MAX_BYTES ? read(path2.join(dir, file)) : null;
45594
- }
45595
- async function siteGenerator(dir) {
45596
- for (const file of ["hugo.toml", "hugo.yaml", "hugo.json", "config.toml"])
45597
- if (/\bbaseURL\b/i.test(await read(path2.join(dir, file)) ?? "")) return "Hugo";
45598
- if (await exists(path2.join(dir, "_config.yml")) || await exists(path2.join(dir, "_layouts")))
45599
- return "Jekyll";
45600
- return null;
45601
- }
45602
- var NEXT_DOCUMENT = (tag, notice) => `// ${OURS}: Next.js's own document, plus the Agentface tag.
45603
- import { Html, Head, Main, NextScript } from 'next/document';
45604
-
45605
- export default function Document() {
45606
- return (
45607
- <Html>
45608
- <Head>
45609
- ${tag}
45610
- </Head>
45611
- <body>
45612
- ${notice ? ` ${notice}
45613
- ` : ""} <Main />
45614
- <NextScript />
45615
- </body>
45616
- </Html>
45617
- );
45618
- }
45619
- `;
45620
- var LINE_NAME = "AgentfaceApi";
45621
- var LINE_USE = new RegExp(`<${LINE_NAME}\\s*/>`);
45622
- var LINE_IMPORT = new RegExp(
45623
- `^import\\s+${LINE_NAME}\\s+from\\s*(['"])\\.\\.?\\/(?:[^'"\\n]*\\/)?agentface\\1;?[ \\t]*$`,
45624
- "m"
45625
- );
45626
- var usesLine = (source) => LINE_USE.test(source) && LINE_IMPORT.test(source);
45627
- var JSX_CODE = /\.(?:jsx|tsx|js|mjs|cjs)$/i;
45628
- function withoutLine(source) {
45629
- if (!usesLine(source)) return source;
45630
- return source.replace(new RegExp(`\\r?\\n[ \\t]*<${LINE_NAME}\\s*\\/>(?=[ \\t]*\\r?\\n)`, "g"), "").replace(new RegExp(`<${LINE_NAME}\\s*\\/>`, "g"), "").replace(
45631
- new RegExp(`^import\\s+${LINE_NAME}\\s+from\\s*(['"])[^'"\\n]+\\1;?[ \\t]*\\r?\\n(\\r?\\n)?`, "m"),
45632
- (match, quote, blank, offset) => blank && offset ? blank : ""
45633
- );
45634
- }
45635
- var GATSBY_SSR = (tag, notice) => {
45636
- const src = tag.match(/\bsrc="([^"]+)"/)[1];
45637
- const data = [...tag.matchAll(/\b(data-[a-z-]+)="([^"]+)"/g)].map(
45638
- ([, name, value]) => `, '${name}': '${value}'`
45639
- );
45640
- const text2 = notice?.match(/>([^<]*)</)[1];
45641
- const load = tag.match(/^<script (async|defer)\b/)?.[1] ?? "defer";
45642
- const props = `key: 'agentface', ${load}: true, src: '${src}'${data.join("")}`;
45643
- return `// ${OURS}: puts the Agentface tag in every page's <head>.
45644
- const React = require('react');
45645
45214
 
45646
- exports.onRenderBody = ({ setHeadComponents${text2 ? ", setPreBodyComponents" : ""} }) => {
45647
- setHeadComponents([
45648
- React.createElement('script', { ${props} }),
45649
- ]);
45650
- ${text2 ? ` setPreBodyComponents([React.createElement('noscript', { key: 'agentface' }, '${text2}')]);
45651
- ` : ""}};
45652
- `;
45653
- };
45215
+ // cli/php.mts
45654
45216
  var phpString = (text2) => `'${text2.replace(/[\\']/g, "\\$&")}'`;
45655
45217
  var PHP_LINES = (tag, notice, own2) => {
45656
45218
  const { service, site } = siteOf(tag);
@@ -45963,206 +45525,688 @@ ${own2}
45963
45525
  return $at === -1 ? $page : substr($page, 0, $at) . $line . substr($page, $at);
45964
45526
  }
45965
45527
  }
45966
- `;
45967
- };
45968
- var DOES = (notice) => `Puts the Agentface tag in every page's head${notice ? ", its notice first in the body, and the notice again, hidden, at the end of the first paragraph" : ""}.`;
45969
- var MU_PLUGIN = (tag, notice) => String.raw`<?php
45970
- /**
45971
- * Plugin Name: Agentface
45972
- * Description: ${DOES(notice)}
45973
- */
45974
- ${about("//", "WordPress runs it on every page by itself, as a must-use plugin, and it puts\nthem in each page made from the theme.")}
45975
- if (!defined('ABSPATH')) {
45976
- exit;
45528
+ `;
45529
+ };
45530
+ var DOES = (notice) => `Puts the Agentface tag in every page's head${notice ? ", its notice first in the body, and the notice again, hidden, at the end of the first paragraph" : ""}.`;
45531
+ var WORDPRESS_OWN = String.raw`
45532
+ // The copy, in the site's options.
45533
+ private static function kept()
45534
+ {
45535
+ return get_option('agentface_lines');
45536
+ }
45537
+
45538
+ private static function keep($kept)
45539
+ {
45540
+ update_option('agentface_lines', $kept, true);
45541
+ }
45542
+
45543
+ // What Agentface answered at $url, or null.
45544
+ private static function fetch($url)
45545
+ {
45546
+ $response = wp_remote_get($url, array(
45547
+ 'timeout' => 2,
45548
+ 'user-agent' => 'agentface-lines/${INIT}',
45549
+ 'headers' => array('Accept' => 'application/json'),
45550
+ ));
45551
+ return !is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200
45552
+ ? wp_remote_retrieve_body($response)
45553
+ : null;
45554
+ }
45555
+ `;
45556
+ var WORDPRESS_HOOK = `// The lines are asked for before the page is made, and go in as it goes out.
45557
+ // A page sent in parts gets them in the part that has the end of its head,
45558
+ // without the line Exa keeps.
45559
+ add_action('template_redirect', function () {
45560
+ AgentfaceLines::lines();
45561
+ ob_start(function ($html, $phase) {
45562
+ return $phase & PHP_OUTPUT_HANDLER_CLEAN ? $html : AgentfaceLines::sent($html, http_response_code(), headers_list());
45563
+ });
45564
+ }, PHP_INT_MIN);
45565
+ `;
45566
+ var MU_PLUGIN = (tag, notice) => String.raw`<?php
45567
+ /**
45568
+ * Plugin Name: Agentface
45569
+ * Description: ${DOES(notice)}
45570
+ */
45571
+ ${about("//", "WordPress runs it on every page by itself, as a must-use plugin, and it puts\nthem in each page made from the theme.")}
45572
+ if (!defined('ABSPATH')) {
45573
+ exit;
45574
+ }
45575
+
45576
+ ${PHP_LINES(tag, notice, WORDPRESS_OWN)}
45577
+ ${WORDPRESS_HOOK}`;
45578
+ var WORDPRESS_PLUGIN = (tag, notice) => String.raw`<?php
45579
+ /**
45580
+ * Plugin Name: Agentface
45581
+ * Plugin URI: https://agentface.com
45582
+ * Description: ${DOES(notice)}
45583
+ * Version: ${INIT}
45584
+ * Requires PHP: 5.6
45585
+ * Author: Agentface
45586
+ */
45587
+ // Agentface's plugin for WordPress, made by agentface ${INIT}. It asks
45588
+ // Agentface for the two lines this site's pages carry for AI agents, the tag
45589
+ // and its notice, so that a change to them reaches the site by itself. It
45590
+ // keeps them an hour and, while Agentface can't be reached, uses the copy it
45591
+ // has: at first the one below. WordPress runs it on every page once it's
45592
+ // activated in Plugins, and it puts them in each page made from the theme.
45593
+ // Deactivating and deleting it there takes it off.
45594
+ if (!defined('ABSPATH')) {
45595
+ exit;
45596
+ }
45597
+
45598
+ // The must-use plugin that npx agentface init adds to a site's own files does
45599
+ // all of this too, and WordPress runs it first: with it there, this one does
45600
+ // nothing.
45601
+ if (!class_exists('AgentfaceLines', false)) {
45602
+ ${PHP_LINES(tag, notice, WORDPRESS_OWN)}
45603
+ ${WORDPRESS_HOOK}}
45604
+ `;
45605
+ var WORDPRESS_UNINSTALL = `<?php
45606
+ if (!defined('WP_UNINSTALL_PLUGIN')) {
45607
+ exit;
45608
+ }
45609
+
45610
+ delete_option('agentface_lines');
45611
+ `;
45612
+ var wordPressFiles = (tag, notice) => ({
45613
+ "agentface/agentface.php": WORDPRESS_PLUGIN(tag, notice),
45614
+ "agentface/uninstall.php": WORDPRESS_UNINSTALL
45615
+ });
45616
+ var PRESTASHOP_MODULE = (tag, notice) => String.raw`<?php
45617
+ ${about("//", "PrestaShop runs it once it's installed in Modules > Module Manager, and it\nputs them in each page the shop makes.")}
45618
+ if (!defined('_PS_VERSION_')) {
45619
+ exit;
45620
+ }
45621
+
45622
+ ${PHP_LINES(
45623
+ tag,
45624
+ notice,
45625
+ String.raw`
45626
+ // The copy, in the shop's settings. Its tags are escaped, since PrestaShop
45627
+ // takes tags out of a setting's text.
45628
+ private static function kept()
45629
+ {
45630
+ return json_decode((string) Configuration::getGlobalValue('AGENTFACE_LINES'), true);
45631
+ }
45632
+
45633
+ private static function keep($kept)
45634
+ {
45635
+ Configuration::updateGlobalValue('AGENTFACE_LINES', json_encode($kept, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT));
45636
+ }
45637
+
45638
+ // What Agentface answered at $url, or null.
45639
+ private static function fetch($url)
45640
+ {
45641
+ if (!function_exists('curl_init')) {
45642
+ return null;
45643
+ }
45644
+ $curl = curl_init($url);
45645
+ curl_setopt_array($curl, array(
45646
+ CURLOPT_RETURNTRANSFER => true,
45647
+ CURLOPT_CONNECTTIMEOUT => 2,
45648
+ CURLOPT_TIMEOUT => 2,
45649
+ CURLOPT_USERAGENT => 'agentface-lines/${INIT}',
45650
+ CURLOPT_HTTPHEADER => array('Accept: application/json'),
45651
+ ));
45652
+ $body = curl_exec($curl);
45653
+ return is_string($body) && curl_getinfo($curl, CURLINFO_HTTP_CODE) === 200 ? $body : null;
45654
+ }
45655
+ `
45656
+ )}
45657
+ class Agentface extends Module
45658
+ {
45659
+ public function __construct()
45660
+ {
45661
+ $this->name = 'agentface';
45662
+ $this->tab = 'front_office_features';
45663
+ $this->version = '1.0.0';
45664
+ $this->author = 'Agentface';
45665
+ $this->need_instance = 0;
45666
+ $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_];
45667
+ parent::__construct();
45668
+ $this->displayName = 'Agentface';
45669
+ $this->description = "${DOES(notice)}";
45670
+ }
45671
+
45672
+ public function install()
45673
+ {
45674
+ return parent::install() && $this->registerHook('actionOutputHTMLBefore');
45675
+ }
45676
+
45677
+ public function uninstall()
45678
+ {
45679
+ Configuration::deleteByName('AGENTFACE_LINES');
45680
+ return parent::uninstall();
45681
+ }
45682
+
45683
+ public function hookActionOutputHTMLBefore($params)
45684
+ {
45685
+ $params['html'] = AgentfaceLines::sent($params['html'], http_response_code(), headers_list());
45686
+ }
45687
+
45688
+ // A shop that installed the module an earlier init wrote still calls it in
45689
+ // every page's head and body, where it put the tag and the notice. The
45690
+ // first page it's called for moves it to the hook above, and gets them
45691
+ // there as before.
45692
+ public function hookDisplayHeader()
45693
+ {
45694
+ if ($this->registerHook('actionOutputHTMLBefore')) {
45695
+ $this->unregisterHook('displayHeader');
45696
+ $this->unregisterHook('displayAfterBodyOpeningTag');
45697
+ }
45698
+ $lines = AgentfaceLines::lines();
45699
+ return $lines[0] . "\n";
45700
+ }
45701
+
45702
+ public function hookDisplayAfterBodyOpeningTag()
45703
+ {
45704
+ $lines = AgentfaceLines::lines();
45705
+ return $lines[1] === '' ? '' : $lines[1] . "\n";
45706
+ }
45707
+ }
45708
+ `;
45709
+ var MU_PLUGIN_HOOKS = (tag, notice) => `<?php
45710
+ /**
45711
+ * Plugin Name: Agentface
45712
+ * Description: Puts the Agentface tag in every page's head${notice ? ", and its notice first in the body" : ""}.
45713
+ */
45714
+ // ${OURS}. WordPress runs it on every page, and \`npx agentface uninstall\` deletes it.
45715
+
45716
+ add_action('wp_head', function () {
45717
+ echo '${tag}' . "\\n";
45718
+ }, PHP_INT_MAX);
45719
+ ${notice ? `
45720
+ add_action('wp_body_open', function () {
45721
+ echo '${notice}' . "\\n";
45722
+ }, PHP_INT_MIN);
45723
+ ` : ""}`;
45724
+ var PRESTASHOP_MODULE_HOOKS = (tag, notice) => `<?php
45725
+ // ${OURS}. PrestaShop runs it on every page once it's installed in Modules > Module Manager, and \`npx agentface uninstall\` deletes it.
45726
+ if (!defined('_PS_VERSION_')) {
45727
+ exit;
45728
+ }
45729
+
45730
+ class Agentface extends Module
45731
+ {
45732
+ public function __construct()
45733
+ {
45734
+ $this->name = 'agentface';
45735
+ $this->tab = 'front_office_features';
45736
+ $this->version = '1.0.0';
45737
+ $this->author = 'Agentface';
45738
+ $this->need_instance = 0;
45739
+ $this->ps_versions_compliancy = ['min' => '1.7.0.0', 'max' => _PS_VERSION_];
45740
+ parent::__construct();
45741
+ $this->displayName = 'Agentface';
45742
+ $this->description = "Puts the Agentface tag in every page's head${notice ? ", and its notice first in the body" : ""}.";
45743
+ }
45744
+
45745
+ public function install()
45746
+ {
45747
+ return parent::install()
45748
+ && $this->registerHook('displayHeader')${notice ? `
45749
+ && $this->registerHook('displayAfterBodyOpeningTag')` : ""};
45750
+ }
45751
+
45752
+ public function hookDisplayHeader()
45753
+ {
45754
+ return '${tag}' . "\\n";
45755
+ }
45756
+ ${notice ? `
45757
+ public function hookDisplayAfterBodyOpeningTag()
45758
+ {
45759
+ return '${notice}' . "\\n";
45760
+ }
45761
+ ` : ""}}
45762
+ `;
45763
+ var PRESTASHOP_MODULE_FILE = "agentface/agentface.php";
45764
+ var prestaShopFiles = (tag, notice) => ({
45765
+ [PRESTASHOP_MODULE_FILE]: PRESTASHOP_MODULE(tag, notice)
45766
+ });
45767
+
45768
+ // cli/zip.mts
45769
+ var CRC_TABLE = Array.from({ length: 256 }, (_, n) => {
45770
+ let c = n;
45771
+ for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
45772
+ return c >>> 0;
45773
+ });
45774
+ function crc32(data) {
45775
+ let c = 4294967295;
45776
+ for (const byte of data) c = CRC_TABLE[(c ^ byte) & 255] ^ c >>> 8;
45777
+ return (c ^ 4294967295) >>> 0;
45778
+ }
45779
+ var concat = (parts) => {
45780
+ const all = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
45781
+ let at = 0;
45782
+ for (const part of parts) {
45783
+ all.set(part, at);
45784
+ at += part.length;
45785
+ }
45786
+ return all;
45787
+ };
45788
+ function zip(files2, { date = /* @__PURE__ */ new Date(), deflate } = {}) {
45789
+ const encoder = new TextEncoder();
45790
+ const time = date.getHours() << 11 | date.getMinutes() << 5 | date.getSeconds() >> 1;
45791
+ const day = date.getFullYear() - 1980 << 9 | date.getMonth() + 1 << 5 | date.getDate();
45792
+ const parts = [];
45793
+ const directory = [];
45794
+ let offset = 0;
45795
+ for (const [name, text2] of Object.entries(files2)) {
45796
+ const data = encoder.encode(text2);
45797
+ const packed = deflate ? deflate(data) : data;
45798
+ const path6 = encoder.encode(name);
45799
+ const shared = new Uint8Array(26);
45800
+ const fields = new DataView(shared.buffer);
45801
+ fields.setUint16(0, 20, true);
45802
+ fields.setUint16(2, 2048, true);
45803
+ fields.setUint16(4, deflate ? 8 : 0, true);
45804
+ fields.setUint16(6, time, true);
45805
+ fields.setUint16(8, day, true);
45806
+ fields.setUint32(10, crc32(data), true);
45807
+ fields.setUint32(14, packed.length, true);
45808
+ fields.setUint32(18, data.length, true);
45809
+ fields.setUint16(22, path6.length, true);
45810
+ const local = new Uint8Array(4);
45811
+ new DataView(local.buffer).setUint32(0, 67324752, true);
45812
+ parts.push(local, shared, path6, packed);
45813
+ const entry2 = new Uint8Array(46);
45814
+ const entryFields = new DataView(entry2.buffer);
45815
+ entryFields.setUint32(0, 33639248, true);
45816
+ entryFields.setUint16(4, 788, true);
45817
+ entry2.set(shared, 6);
45818
+ entryFields.setUint32(38, 33188 * 65536, true);
45819
+ entryFields.setUint32(42, offset, true);
45820
+ directory.push(entry2, path6);
45821
+ offset += 4 + shared.length + path6.length + packed.length;
45822
+ }
45823
+ const size = directory.reduce((total, part) => total + part.length, 0);
45824
+ const end = new Uint8Array(22);
45825
+ const endFields = new DataView(end.buffer);
45826
+ endFields.setUint32(0, 101010256, true);
45827
+ endFields.setUint16(8, Object.keys(files2).length, true);
45828
+ endFields.setUint16(10, Object.keys(files2).length, true);
45829
+ endFields.setUint32(12, size, true);
45830
+ endFields.setUint32(16, offset, true);
45831
+ return concat([...parts, ...directory, end]);
45832
+ }
45833
+
45834
+ // cli/heads.mts
45835
+ var stamped = (tag) => tag.replace(/><\/script>$/, ` data-init="${INIT}"></script>`);
45836
+ var EXTENSIONS = [
45837
+ "html",
45838
+ "htm",
45839
+ "php",
45840
+ "njk",
45841
+ "liquid",
45842
+ "hbs",
45843
+ "handlebars",
45844
+ "mustache",
45845
+ "ejs",
45846
+ "erb",
45847
+ "twig",
45848
+ "jinja",
45849
+ "jinja2",
45850
+ "j2",
45851
+ "tmpl",
45852
+ "tpl",
45853
+ "astro",
45854
+ "heex"
45855
+ ];
45856
+ var MARKUP = new RegExp(`\\.(?:${EXTENSIONS.join("|")})$`, "i");
45857
+ var COMPONENT = /\.(?:[cm]?[jt]sx?|vue|svelte|mdx)$/i;
45858
+ var LAYOUTS = [
45859
+ /(?:^|\/)app\/(?:.+\/)?layout\.[cm]?[jt]sx?$/,
45860
+ /(?:^|\/)pages\/_document\.[cm]?[jt]sx?$/,
45861
+ /(?:^|\/)app\/root\.[cm]?[jt]sx?$/,
45862
+ /(?:^|\/)routes\/__root\.[cm]?[jt]sx?$/,
45863
+ /(?:^|\/)src\/html\.[cm]?[jt]sx?$/
45864
+ ];
45865
+ var SKIP = /* @__PURE__ */ new Set([
45866
+ "node_modules",
45867
+ "bower_components",
45868
+ "vendor",
45869
+ "dist",
45870
+ "build",
45871
+ "out",
45872
+ "_site",
45873
+ "coverage",
45874
+ "tmp",
45875
+ "temp",
45876
+ "test",
45877
+ "tests",
45878
+ "__tests__",
45879
+ "__mocks__",
45880
+ "fixtures",
45881
+ "__fixtures__",
45882
+ "e2e",
45883
+ "cypress",
45884
+ "playwright",
45885
+ "storybook-static",
45886
+ "wp-admin",
45887
+ "wp-includes",
45888
+ // A Python environment's packages, and Elixir's builds.
45889
+ "site-packages",
45890
+ "dist-packages",
45891
+ "__pycache__",
45892
+ "_build"
45893
+ ]);
45894
+ var MAIL = /mail/i;
45895
+ var PRINTED = /(?:^|[-_.])(?:pdfs?|invoices?|receipts?|print(?:able)?)(?=$|[-_.])/i;
45896
+ var notMail = (name) => !MAIL.test(name) && !PRINTED.test(name);
45897
+ var AMP = /<html\b[^>]*\s(?:amp|⚡)[\s>=/]/i;
45898
+ var CODE = /<\?(?!xml\b)[\s\S]*?(?:\?>|$)|<%[\s\S]*?(?:%>|$)/g;
45899
+ function inCode(source, at) {
45900
+ for (const code of source.matchAll(CODE)) {
45901
+ if (code.index > at) return false;
45902
+ if (at < code.index + code[0].length) return true;
45903
+ }
45904
+ return false;
45905
+ }
45906
+ var MAX_FILES = 2e4;
45907
+ var MAX_BYTES = 1e6;
45908
+ var CONFIG_HEAD = {
45909
+ nuxt: ["Nuxt", "`app.head.script` in nuxt.config"],
45910
+ "@docusaurus/core": ["Docusaurus", "`scripts` in docusaurus.config"],
45911
+ vitepress: ["VitePress", "`head` in .vitepress/config"]
45912
+ };
45913
+ var FRAMEWORKS = [
45914
+ ["next", "Next.js"],
45915
+ ["@tanstack/react-start", "TanStack Start"],
45916
+ ["@react-router/dev", "React Router"],
45917
+ ["@remix-run/dev", "Remix"],
45918
+ ["gatsby", "Gatsby"],
45919
+ ["@sveltejs/kit", "SvelteKit"],
45920
+ ["astro", "Astro"],
45921
+ ["@11ty/eleventy", "Eleventy"],
45922
+ ["@angular/core", "Angular"],
45923
+ ["react-scripts", "Create React App"],
45924
+ ["@vue/cli-service", "Vue CLI"],
45925
+ ["vite", "Vite"]
45926
+ ];
45927
+ var read = (file) => readFile2(file, "utf8").catch(() => null);
45928
+ var exists = (file) => stat2(file).then(
45929
+ () => true,
45930
+ () => false
45931
+ );
45932
+ var THEME = /^(?:[ \t]*<\?php)?[ \t/*#@]*Theme Name\s*:/im;
45933
+ async function isWordPress(dir) {
45934
+ if (THEME.test((await read(path2.join(dir, "style.css")) ?? "").slice(0, 8192))) return true;
45935
+ for (const name of ["wp-content", "wp-includes"]) if (await exists(path2.join(dir, name))) return true;
45936
+ for (let at = path2.resolve(dir); ; at = path2.dirname(at)) {
45937
+ if (path2.basename(at) === "wp-content" || await exists(path2.join(at, "wp-config.php"))) return true;
45938
+ if (path2.dirname(at) === at) return false;
45939
+ }
45940
+ }
45941
+ async function contentFolder(dir) {
45942
+ const here = path2.resolve(dir);
45943
+ for (let at = here; ; at = path2.dirname(at)) {
45944
+ if (path2.basename(at) === "wp-content") return at;
45945
+ const content = path2.join(at, "wp-content");
45946
+ if ((at === here || await exists(path2.join(at, "wp-config.php"))) && await exists(content))
45947
+ return content;
45948
+ if (path2.dirname(at) === at) return null;
45949
+ }
45950
+ }
45951
+ async function wordPressFile(dir) {
45952
+ const content = await contentFolder(dir);
45953
+ return content && path2.relative(dir, path2.join(content, "mu-plugins", "agentface.php")).split(path2.sep).join("/");
45954
+ }
45955
+ var wordPressPage = (html) => /\/wp-(?:content|includes)\/|["']https:\/\/api\.w\.org\/["']|<meta\b[^>]*\bcontent=["']WordPress\b/i.test(
45956
+ html
45957
+ );
45958
+ var wordPressManual = (lead) => ({
45959
+ reason: `${lead} Run in the site's folder, the one with wp-config.php, init adds a plugin of its own that puts the tag on every page, with nothing to activate. It never edits WordPress's, its plugins' or its theme's files: updates put them back and take the tag away, and a header plugin or page builder, such as Elementor's, can replace the theme's header, so that a tag put there reaches no page.`,
45960
+ how: "Upload the plugin init writes here as a zip",
45961
+ upload: true
45962
+ });
45963
+ var wordPressZip = (tag, notice) => zip(wordPressFiles(tag, notice), { deflate: deflateRawSync });
45964
+ var prestaShopZip = (tag, notice) => zip(prestaShopFiles(tag, notice), { deflate: deflateRawSync });
45965
+ var SHOP = /\b_PS_[A-Z_]+_\b/;
45966
+ async function shopFolder(dir) {
45967
+ for (let at = path2.resolve(dir); ; at = path2.dirname(at)) {
45968
+ if (SHOP.test(await read(path2.join(at, "config", "defines.inc.php")) ?? "")) return at;
45969
+ if (path2.dirname(at) === at) return null;
45970
+ }
45971
+ }
45972
+ async function prestaShopFile(dir) {
45973
+ const shop = await shopFolder(dir);
45974
+ return shop && path2.relative(dir, path2.join(shop, "modules", PRESTASHOP_MODULE_FILE)).split(path2.sep).join("/");
45975
+ }
45976
+ async function prestaShopTheme(dir) {
45977
+ return /^name\s*:/m.test(await read(path2.join(dir, "config", "theme.yml")) ?? "") && await exists(path2.join(dir, "templates"));
45978
+ }
45979
+ var prestaShopPage = (html) => /\bvar\s+prestashop\s*=/.test(html);
45980
+ var KEY = /\/s\/(site-[a-z0-9-]+)\.js(?=[?#"'`\s]|$)/;
45981
+ var BRACES = String.raw`\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}`;
45982
+ var ATTRIBUTES2 = `(?:${BRACES}|[^>])*?`;
45983
+ var TAG = new RegExp(
45984
+ `<script\\b${ATTRIBUTES2}${KEY.source}${ATTRIBUTES2}(?:\\/>|>\\s*<\\/script\\s*>)`,
45985
+ "gi"
45986
+ );
45987
+ var ATTRIBUTE = new RegExp(
45988
+ `(${BRACES})|([^\\s"'<>/={}]+)(?:\\s*=\\s*(${BRACES}|"[^"]*"|'[^']*'|[^\\s"'<>=]+))?`,
45989
+ "g"
45990
+ );
45991
+ var NOTICE = /<noscript\b[^>]*>[^<]*\/s\/(site-[a-z0-9-]+)\.md[^<]*<\/noscript\s*>/i;
45992
+ var MADE_NOTICE = /createElement\(\s*['"]noscript['"][^()]*\/s\/(site-[a-z0-9-]+)\.md/;
45993
+ var LIST = /\/s\/(site-[a-z0-9-]+)\.md(?![\w-])/;
45994
+ var BODY = /<body(?=[\s>/])(?:<\?[\s\S]*?\?>|<%[\s\S]*?%>|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}|"[^"]*"|'[^']*'|[^>])*>/i;
45995
+ var onItsLine = (pattern) => new RegExp(`(\\r?\\n[ \\t]*)?${pattern.source}`, "gi");
45996
+ function tagKey(source) {
45997
+ return source.match(KEY)?.[1] ?? null;
45998
+ }
45999
+ function noticeKey(source) {
46000
+ return source.match(NOTICE)?.[1] ?? null;
46001
+ }
46002
+ var linesIn = (source) => ({
46003
+ tag: source.match(TAG)?.[0] ?? null,
46004
+ notice: source.match(NOTICE)?.[0] ?? null
46005
+ });
46006
+ var squash = (text2) => text2.replace(/\s+/g, " ").trim();
46007
+ var said2 = (value = "") => squash(value.replace(/^\{\s*(["'`][\s\S]*["'`])\s*\}$/, "$1").replace(/^(["'`])([\s\S]*)\1$/, "$2"));
46008
+ function attributesOf(tag) {
46009
+ const inside = tag.replace(/^<script\b/i, "").replace(/(?:\/>|>\s*<\/script\s*>)$/i, "");
46010
+ return [...inside.matchAll(ATTRIBUTE)].map(
46011
+ ([, braces, name, value]) => braces ? { name: null, value: void 0, text: braces } : { name: name.toLowerCase(), value, text: value === void 0 ? name : `${name}=${value}` }
46012
+ );
46013
+ }
46014
+ function updatedTag(old, tag) {
46015
+ const now = attributesOf(tag);
46016
+ const was = attributesOf(old);
46017
+ const mine = initsOwn(was, now);
46018
+ const init2 = (list2) => list2.some(({ name }) => name === "data-init");
46019
+ const rest = (list2) => list2.filter(({ name }) => name !== "data-init");
46020
+ const current2 = rest(mine).length === rest(now).length && (init2(mine) || !init2(now)) && rest(now).every(({ name, value }) => {
46021
+ const same = mine.find((attribute2) => attribute2.name === name);
46022
+ return same && (value === void 0 || said2(same.value) === said2(value));
46023
+ });
46024
+ if (current2) return old;
46025
+ const kept = was.filter((attribute2) => !mine.includes(attribute2)).map(({ text: text2 }) => text2);
46026
+ return kept.length ? tag.replace(/^<script\b/, () => `<script ${kept.join(" ")}`) : tag;
46027
+ }
46028
+ function initsOwn(was, now) {
46029
+ const names = /* @__PURE__ */ new Set(["src", "async", "defer", "data-init", ...now.map(({ name }) => name)]);
46030
+ return was.filter(({ name, value }) => name !== null && (names.has(name) || LIST.test(value ?? "")));
46031
+ }
46032
+ function ownersAttributes(old) {
46033
+ const was = attributesOf(old);
46034
+ const mine = initsOwn(was, []);
46035
+ return was.filter((attribute2) => !mine.includes(attribute2)).map(({ text: text2 }) => text2);
46036
+ }
46037
+ function updatedNotice(old, notice) {
46038
+ const parts = (line) => line.match(/^<noscript\b([^>]*)>([^<]*)<\/noscript\s*>$/i) ?? [];
46039
+ const [, attributes = "", text2 = ""] = parts(old);
46040
+ if (squash(text2) === squash(parts(notice)[2] ?? "")) return old;
46041
+ return squash(attributes) ? notice.replace(/^<noscript\b/, () => `<noscript ${squash(attributes)}`) : notice;
46042
+ }
46043
+ function tagToReplace(source, tag) {
46044
+ const old = source.match(TAG)?.[0];
46045
+ const next2 = old && updatedTag(old, tag.replace(/\sdata-init="[^"]*"/, ""));
46046
+ return next2 && next2 !== old ? updatedTag(old, tag) : null;
46047
+ }
46048
+ function staleNotice(source, notice) {
46049
+ const key = noticeKey(notice);
46050
+ return [...source.matchAll(new RegExp(NOTICE.source, "gi"))].some(
46051
+ ([old, its]) => its === key && updatedNotice(old, notice) !== old
46052
+ );
46053
+ }
46054
+ function oldWords(source, words, key) {
46055
+ const rest = source.replace(TAG, "").replace(new RegExp(NOTICE.source, "gi"), "");
46056
+ for (const match of rest.matchAll(new RegExp(LIST.source, "g"))) {
46057
+ if (match[1] !== key) continue;
46058
+ const before = rest.slice(Math.max(0, match.index - 400), match.index);
46059
+ const written = before.match(/([^"'`<>{}]*?)\s*https?:\/\/[^\s"'`<>{}]*$/)?.[1];
46060
+ if (written && squash(written) && squash(written) !== squash(words)) return true;
46061
+ }
46062
+ return false;
46063
+ }
46064
+ function indentUnit(source) {
46065
+ return source.match(/^(\t| {2,4})\S/m)?.[1] ?? " ";
46066
+ }
46067
+ var indentOf = (line) => line.match(/^[ \t]*/)[0];
46068
+ function addTag(source, tag) {
46069
+ let first = true;
46070
+ const replaced = source.replace(onItsLine(TAG), (match, line) => {
46071
+ if (!first) return "";
46072
+ first = false;
46073
+ return (line ?? "") + updatedTag(match.slice(line?.length ?? 0), tag);
46074
+ });
46075
+ if (!first) return replaced;
46076
+ const eol = source.includes("\r\n") ? "\r\n" : "\n";
46077
+ const at = headEnd(source);
46078
+ const close = at !== -1 && /^<\/head\s*>/i.test(source.slice(at)) ? at : -1;
46079
+ if (close !== -1) {
46080
+ const lineStart = source.lastIndexOf("\n", close - 1) + 1;
46081
+ const before = source.slice(lineStart, close);
46082
+ if (!/^[ \t]*$/.test(before)) return source.slice(0, close) + tag + source.slice(close);
46083
+ const previous = source.slice(0, lineStart).split(/\r?\n/).findLast((line) => line.trim());
46084
+ const sibling = indentOf(previous ?? "");
46085
+ const indent = previous && !/<head\b[^>]*>\s*$/i.test(previous) && sibling.startsWith(before) ? sibling : before + indentUnit(source);
46086
+ return source.slice(0, lineStart) + indent + tag + eol + source.slice(lineStart);
46087
+ }
46088
+ const html = /<html\b[^>]*>/.exec(source);
46089
+ if (!html) return null;
46090
+ const end = html.index + html[0].length;
46091
+ const child = source.slice(end).match(/^\r?\n([ \t]*)\S/)?.[1];
46092
+ if (child === void 0) return source.slice(0, end) + `<head>${tag}</head>` + source.slice(end);
46093
+ const outer = indentOf(source.slice(source.lastIndexOf("\n", html.index) + 1));
46094
+ const step = child.length > outer.length && child.startsWith(outer) ? child.slice(outer.length) : indentUnit(source);
46095
+ const lines = [`${child}<head>`, `${child}${step}${tag}`, `${child}</head>`];
46096
+ return source.slice(0, end) + eol + lines.join(eol) + source.slice(end);
46097
+ }
46098
+ function addNotice(source, notice) {
46099
+ let first = true;
46100
+ const replaced = source.replace(onItsLine(NOTICE), (match, line) => {
46101
+ if (!first) return "";
46102
+ first = false;
46103
+ return (line ?? "") + updatedNotice(match.slice(line?.length ?? 0), notice);
46104
+ });
46105
+ if (!first) return replaced;
46106
+ const body = BODY.exec(source);
46107
+ if (!body) return null;
46108
+ const end = body.index + body[0].length;
46109
+ const next2 = source.slice(end).match(/^[ \t]*\r?\n([ \t]*)(.*)/);
46110
+ if (!next2) return source.slice(0, end) + notice + source.slice(end);
46111
+ const eol = source.includes("\r\n") ? "\r\n" : "\n";
46112
+ const outer = indentOf(source.slice(source.lastIndexOf("\n", body.index) + 1));
46113
+ const indent = next2[2].trim() && !/^<\/body\b/i.test(next2[2]) ? next2[1] : outer + indentUnit(source);
46114
+ return source.slice(0, end) + eol + indent + notice + source.slice(end);
46115
+ }
46116
+ function gitFiles(dir) {
46117
+ return new Promise((resolve2) => {
46118
+ execFile2(
46119
+ "git",
46120
+ ["ls-files", "--cached", "--others", "--exclude-standard", "-z"],
46121
+ { cwd: dir, maxBuffer: 64 * 1024 * 1024 },
46122
+ (error, stdout) => resolve2(error ? null : [...new Set(stdout.split("\0").filter(Boolean))].sort())
46123
+ );
46124
+ });
46125
+ }
46126
+ async function files(dir, skip) {
46127
+ const kept = (name) => (!name.startsWith(".") || name === ".vitepress") && !skip.has(name) && notMail(name);
46128
+ const tracked = await gitFiles(dir);
46129
+ if (tracked)
46130
+ return {
46131
+ git: true,
46132
+ files: tracked.filter((file) => file.split("/").slice(0, -1).every(kept)).slice(0, MAX_FILES)
46133
+ };
46134
+ const found = [];
46135
+ const visit = async (rel) => {
46136
+ const entries = await readdir(path2.join(dir, rel), { withFileTypes: true }).catch(() => []);
46137
+ for (const entry2 of entries.sort((a, b) => a.name.localeCompare(b.name))) {
46138
+ const file = rel ? `${rel}/${entry2.name}` : entry2.name;
46139
+ if (entry2.isDirectory()) {
46140
+ if (kept(entry2.name)) await visit(file);
46141
+ } else if (entry2.isFile() && found.length < MAX_FILES) found.push(file);
46142
+ }
46143
+ };
46144
+ await visit("");
46145
+ return { git: false, files: found };
46146
+ }
46147
+ async function contents(dir, file) {
46148
+ const info = await stat2(path2.join(dir, file)).catch(() => null);
46149
+ return info?.isFile() && info.size <= MAX_BYTES ? read(path2.join(dir, file)) : null;
45977
46150
  }
45978
-
45979
- ${PHP_LINES(
45980
- tag,
45981
- notice,
45982
- String.raw`
45983
- // The copy, in the site's options.
45984
- private static function kept()
45985
- {
45986
- return get_option('agentface_lines');
45987
- }
45988
-
45989
- private static function keep($kept)
45990
- {
45991
- update_option('agentface_lines', $kept, true);
45992
- }
45993
-
45994
- // What Agentface answered at $url, or null.
45995
- private static function fetch($url)
45996
- {
45997
- $response = wp_remote_get($url, array(
45998
- 'timeout' => 2,
45999
- 'user-agent' => 'agentface-lines/${INIT}',
46000
- 'headers' => array('Accept' => 'application/json'),
46001
- ));
46002
- return !is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200
46003
- ? wp_remote_retrieve_body($response)
46004
- : null;
46005
- }
46006
- `
46007
- )}
46008
- // The lines are asked for before the page is made, and go in as it goes out.
46009
- // A page sent in parts gets them in the part that has the end of its head,
46010
- // without the line Exa keeps.
46011
- add_action('template_redirect', function () {
46012
- AgentfaceLines::lines();
46013
- ob_start(function ($html, $phase) {
46014
- return $phase & PHP_OUTPUT_HANDLER_CLEAN ? $html : AgentfaceLines::sent($html, http_response_code(), headers_list());
46015
- });
46016
- }, PHP_INT_MIN);
46017
- `;
46018
- var PRESTASHOP_MODULE = (tag, notice) => String.raw`<?php
46019
- ${about("//", "PrestaShop runs it once it's installed in Modules > Module Manager, and it\nputs them in each page the shop makes.")}
46020
- if (!defined('_PS_VERSION_')) {
46021
- exit;
46151
+ async function siteGenerator(dir) {
46152
+ for (const file of ["hugo.toml", "hugo.yaml", "hugo.json", "config.toml"])
46153
+ if (/\bbaseURL\b/i.test(await read(path2.join(dir, file)) ?? "")) return "Hugo";
46154
+ if (await exists(path2.join(dir, "_config.yml")) || await exists(path2.join(dir, "_layouts")))
46155
+ return "Jekyll";
46156
+ return null;
46022
46157
  }
46158
+ var NEXT_DOCUMENT = (tag, notice) => `// ${OURS}: Next.js's own document, plus the Agentface tag.
46159
+ import { Html, Head, Main, NextScript } from 'next/document';
46023
46160
 
46024
- ${PHP_LINES(
46025
- tag,
46026
- notice,
46027
- String.raw`
46028
- // The copy, in the shop's settings. Its tags are escaped, since PrestaShop
46029
- // takes tags out of a setting's text.
46030
- private static function kept()
46031
- {
46032
- return json_decode((string) Configuration::getGlobalValue('AGENTFACE_LINES'), true);
46033
- }
46034
-
46035
- private static function keep($kept)
46036
- {
46037
- Configuration::updateGlobalValue('AGENTFACE_LINES', json_encode($kept, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT));
46038
- }
46039
-
46040
- // What Agentface answered at $url, or null.
46041
- private static function fetch($url)
46042
- {
46043
- if (!function_exists('curl_init')) {
46044
- return null;
46045
- }
46046
- $curl = curl_init($url);
46047
- curl_setopt_array($curl, array(
46048
- CURLOPT_RETURNTRANSFER => true,
46049
- CURLOPT_CONNECTTIMEOUT => 2,
46050
- CURLOPT_TIMEOUT => 2,
46051
- CURLOPT_USERAGENT => 'agentface-lines/${INIT}',
46052
- CURLOPT_HTTPHEADER => array('Accept: application/json'),
46053
- ));
46054
- $body = curl_exec($curl);
46055
- return is_string($body) && curl_getinfo($curl, CURLINFO_HTTP_CODE) === 200 ? $body : null;
46056
- }
46057
- `
46058
- )}
46059
- class Agentface extends Module
46060
- {
46061
- public function __construct()
46062
- {
46063
- $this->name = 'agentface';
46064
- $this->tab = 'front_office_features';
46065
- $this->version = '1.0.0';
46066
- $this->author = 'Agentface';
46067
- $this->need_instance = 0;
46068
- $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_];
46069
- parent::__construct();
46070
- $this->displayName = 'Agentface';
46071
- $this->description = "${DOES(notice)}";
46072
- }
46073
-
46074
- public function install()
46075
- {
46076
- return parent::install() && $this->registerHook('actionOutputHTMLBefore');
46077
- }
46078
-
46079
- public function uninstall()
46080
- {
46081
- Configuration::deleteByName('AGENTFACE_LINES');
46082
- return parent::uninstall();
46083
- }
46084
-
46085
- public function hookActionOutputHTMLBefore($params)
46086
- {
46087
- $params['html'] = AgentfaceLines::sent($params['html'], http_response_code(), headers_list());
46088
- }
46089
-
46090
- // A shop that installed the module an earlier init wrote still calls it in
46091
- // every page's head and body, where it put the tag and the notice. The
46092
- // first page it's called for moves it to the hook above, and gets them
46093
- // there as before.
46094
- public function hookDisplayHeader()
46095
- {
46096
- if ($this->registerHook('actionOutputHTMLBefore')) {
46097
- $this->unregisterHook('displayHeader');
46098
- $this->unregisterHook('displayAfterBodyOpeningTag');
46099
- }
46100
- $lines = AgentfaceLines::lines();
46101
- return $lines[0] . "\n";
46102
- }
46103
-
46104
- public function hookDisplayAfterBodyOpeningTag()
46105
- {
46106
- $lines = AgentfaceLines::lines();
46107
- return $lines[1] === '' ? '' : $lines[1] . "\n";
46108
- }
46161
+ export default function Document() {
46162
+ return (
46163
+ <Html>
46164
+ <Head>
46165
+ ${tag}
46166
+ </Head>
46167
+ <body>
46168
+ ${notice ? ` ${notice}
46169
+ ` : ""} <Main />
46170
+ <NextScript />
46171
+ </body>
46172
+ </Html>
46173
+ );
46109
46174
  }
46110
46175
  `;
46111
- var MU_PLUGIN_HOOKS = (tag, notice) => `<?php
46112
- /**
46113
- * Plugin Name: Agentface
46114
- * Description: Puts the Agentface tag in every page's head${notice ? ", and its notice first in the body" : ""}.
46115
- */
46116
- // ${OURS}. WordPress runs it on every page, and \`npx agentface uninstall\` deletes it.
46117
-
46118
- add_action('wp_head', function () {
46119
- echo '${tag}' . "\\n";
46120
- }, PHP_INT_MAX);
46121
- ${notice ? `
46122
- add_action('wp_body_open', function () {
46123
- echo '${notice}' . "\\n";
46124
- }, PHP_INT_MIN);
46125
- ` : ""}`;
46126
- var PRESTASHOP_MODULE_HOOKS = (tag, notice) => `<?php
46127
- // ${OURS}. PrestaShop runs it on every page once it's installed in Modules > Module Manager, and \`npx agentface uninstall\` deletes it.
46128
- if (!defined('_PS_VERSION_')) {
46129
- exit;
46176
+ var LINE_NAME = "AgentfaceApi";
46177
+ var LINE_USE = new RegExp(`<${LINE_NAME}\\s*/>`);
46178
+ var LINE_IMPORT = new RegExp(
46179
+ `^import\\s+${LINE_NAME}\\s+from\\s*(['"])\\.\\.?\\/(?:[^'"\\n]*\\/)?agentface\\1;?[ \\t]*$`,
46180
+ "m"
46181
+ );
46182
+ var usesLine = (source) => LINE_USE.test(source) && LINE_IMPORT.test(source);
46183
+ var JSX_CODE = /\.(?:jsx|tsx|js|mjs|cjs)$/i;
46184
+ function withoutLine(source) {
46185
+ if (!usesLine(source)) return source;
46186
+ return source.replace(new RegExp(`\\r?\\n[ \\t]*<${LINE_NAME}\\s*\\/>(?=[ \\t]*\\r?\\n)`, "g"), "").replace(new RegExp(`<${LINE_NAME}\\s*\\/>`, "g"), "").replace(
46187
+ new RegExp(`^import\\s+${LINE_NAME}\\s+from\\s*(['"])[^'"\\n]+\\1;?[ \\t]*\\r?\\n(\\r?\\n)?`, "m"),
46188
+ (match, quote, blank, offset) => blank && offset ? blank : ""
46189
+ );
46130
46190
  }
46191
+ var GATSBY_SSR = (tag, notice) => {
46192
+ const src = tag.match(/\bsrc="([^"]+)"/)[1];
46193
+ const data = [...tag.matchAll(/\b(data-[a-z-]+)="([^"]+)"/g)].map(
46194
+ ([, name, value]) => `, '${name}': '${value}'`
46195
+ );
46196
+ const text2 = notice?.match(/>([^<]*)</)[1];
46197
+ const load = tag.match(/^<script (async|defer)\b/)?.[1] ?? "defer";
46198
+ const props = `key: 'agentface', ${load}: true, src: '${src}'${data.join("")}`;
46199
+ return `// ${OURS}: puts the Agentface tag in every page's <head>.
46200
+ const React = require('react');
46131
46201
 
46132
- class Agentface extends Module
46133
- {
46134
- public function __construct()
46135
- {
46136
- $this->name = 'agentface';
46137
- $this->tab = 'front_office_features';
46138
- $this->version = '1.0.0';
46139
- $this->author = 'Agentface';
46140
- $this->need_instance = 0;
46141
- $this->ps_versions_compliancy = ['min' => '1.7.0.0', 'max' => _PS_VERSION_];
46142
- parent::__construct();
46143
- $this->displayName = 'Agentface';
46144
- $this->description = "Puts the Agentface tag in every page's head${notice ? ", and its notice first in the body" : ""}.";
46145
- }
46146
-
46147
- public function install()
46148
- {
46149
- return parent::install()
46150
- && $this->registerHook('displayHeader')${notice ? `
46151
- && $this->registerHook('displayAfterBodyOpeningTag')` : ""};
46152
- }
46153
-
46154
- public function hookDisplayHeader()
46155
- {
46156
- return '${tag}' . "\\n";
46157
- }
46158
- ${notice ? `
46159
- public function hookDisplayAfterBodyOpeningTag()
46160
- {
46161
- return '${notice}' . "\\n";
46162
- }
46163
- ` : ""}}
46202
+ exports.onRenderBody = ({ setHeadComponents${text2 ? ", setPreBodyComponents" : ""} }) => {
46203
+ setHeadComponents([
46204
+ React.createElement('script', { ${props} }),
46205
+ ]);
46206
+ ${text2 ? ` setPreBodyComponents([React.createElement('noscript', { key: 'agentface' }, '${text2}')]);
46207
+ ` : ""}};
46164
46208
  `;
46165
- var prestaShopZip = (tag, notice) => zip({ [PRESTASHOP_MODULE_FILE]: PRESTASHOP_MODULE(tag, notice) });
46209
+ };
46166
46210
  async function project(dir) {
46167
46211
  const pkg = JSON.parse(await read(path2.join(dir, "package.json")) ?? "null");
46168
46212
  const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
@@ -57901,6 +57945,7 @@ function decodeEntities(s) {
57901
57945
 
57902
57946
  // worker/http.ts
57903
57947
  var USER_AGENT = "AgentfaceFetcher/0.1 (+https://agentface.com)";
57948
+ var HOMEPAGE_BYTES = 2e6;
57904
57949
  async function readStart(response, limit) {
57905
57950
  if (!response.body) return "";
57906
57951
  const reader = response.body.getReader();
@@ -57914,9 +57959,9 @@ async function readStart(response, limit) {
57914
57959
  }
57915
57960
  await reader.cancel().catch(() => {
57916
57961
  });
57917
- return new TextDecoder().decode(concat(chunks, length).subarray(0, limit));
57962
+ return new TextDecoder().decode(concat2(chunks, length).subarray(0, limit));
57918
57963
  }
57919
- function concat(chunks, length) {
57964
+ function concat2(chunks, length) {
57920
57965
  const bytes = new Uint8Array(length);
57921
57966
  let offset = 0;
57922
57967
  for (const chunk of chunks) {
@@ -58008,7 +58053,7 @@ function blockedBy(policies, load) {
58008
58053
  if (scripts) {
58009
58054
  const sources = policy.directives.get(scripts);
58010
58055
  const dynamic = keyword(sources, "'strict-dynamic'");
58011
- const allowed = load.nonce && hasNonce(sources, load.nonce) || (dynamic ? load.added : sources.some((source) => sourceMatches(source, script2, page2)));
58056
+ const allowed = load.nonce && hasNonce(sources, load.nonce) || !dynamic && sources.some((source) => sourceMatches(source, script2, page2));
58012
58057
  if (!allowed) {
58013
58058
  result2.script = true;
58014
58059
  if (dynamic) result2.nonce = { directive: scripts, named: sources.some((s) => /^'nonce-/i.test(s)) };
@@ -58068,7 +58113,7 @@ async function readHomepage(origin, fetcher) {
58068
58113
  await response.body?.cancel();
58069
58114
  return { unread: `it answered HTTP ${response.status}` };
58070
58115
  }
58071
- const html = await readStart(response, 2e5);
58116
+ const html = await readStart(response, HOMEPAGE_BYTES);
58072
58117
  const policies = pagePolicies(response.headers.get("content-security-policy"), html);
58073
58118
  return { url: response.url || origin + "/", html, policies };
58074
58119
  } catch (error) {
@@ -58086,7 +58131,7 @@ function liveNonce(html, id) {
58086
58131
  }
58087
58132
  return void 0;
58088
58133
  }
58089
- function tagBlocked(homepage, site, { added = false } = {}) {
58134
+ function tagBlocked(homepage, site) {
58090
58135
  const src = site.tag.match(/\bsrc="([^"]+)"/)?.[1];
58091
58136
  if ("unread" in homepage || !homepage.policies.length || !src) return null;
58092
58137
  const nonce = liveNonce(homepage.html, site.id);
@@ -58094,8 +58139,7 @@ function tagBlocked(homepage, site, { added = false } = {}) {
58094
58139
  page: homepage.url,
58095
58140
  script: src,
58096
58141
  events: new URL("/e", src).href,
58097
- nonce,
58098
- added: nonce === void 0 && added
58142
+ nonce
58099
58143
  });
58100
58144
  return blocked.length ? advice(blocked, new URL(src).origin) : null;
58101
58145
  }
@@ -58785,7 +58829,7 @@ function nextSteps(site, service, own2) {
58785
58829
  return site.expiresAt ? `Then run \`${check2}\` here: once ${site.origin}'s homepage has the tag, that confirms the site is yours. Agentface also confirms it by itself when the site's first events arrive, but a quiet site may send none in time: until it's confirmed, Agentface deletes ${site.id} at ${when(site.expiresAt)}. If that happens first, run \`npx agentface init\` again.` : `Then \`${check2}\` shows whether ${site.origin}'s homepage has the tag.`;
58786
58830
  if (saved)
58787
58831
  return site.expiresAt ? `Then run \`${check2}\`: once ${site.origin}'s homepage has the tag, that confirms the site is yours. Agentface also confirms it by itself when the site's first events arrive, but a quiet site may send none in time: until it's confirmed, Agentface deletes ${site.id} at ${when(site.expiresAt)}. To see these steps again without registering the site another time, run \`npx agentface init ${site.id}${serviceFlag(service)}\`.` : `Then \`${check2}\` shows whether ${site.origin}'s homepage has the tag.`;
58788
- return site.expiresAt ? `Deploy it as usual, then run \`${check2}\` here: once ${site.origin}'s homepage has the tag, in its HTML or in the Google Tag Manager container it loads, that confirms the site is yours. Agentface also confirms it by itself when the site's first events arrive, but a quiet site may send none in time: until it's confirmed, Agentface deletes ${site.id} at ${when(site.expiresAt)}. If that happens first, run \`npx agentface init\` again.` : `Deploy it as usual. \`${check2}\` shows whether ${site.origin}'s homepage has the tag.`;
58832
+ return site.expiresAt ? `Deploy it as usual, then run \`${check2}\` here: once ${site.origin}'s homepage has the tag, that confirms the site is yours. Agentface also confirms it by itself when the site's first events arrive, but a quiet site may send none in time: until it's confirmed, Agentface deletes ${site.id} at ${when(site.expiresAt)}. If that happens first, run \`npx agentface init\` again.` : `Deploy it as usual. \`${check2}\` shows whether ${site.origin}'s homepage has the tag.`;
58789
58833
  }
58790
58834
  function policyWarning(site, advice2) {
58791
58835
  return advice2 ? `${site.origin}'s Content Security Policy, the list of hosts its pages may use, doesn't let them ${advice2.effect}. ${advice2.fixes}` : null;
@@ -58806,8 +58850,8 @@ ${warning ? `**Content Security Policy.** ${markdown(warning)}
58806
58850
  **Uninstall.** ${update ? `Run \`npx agentface uninstall\`, or delete ${lines}. Reverting this pull request doesn't uninstall: it puts the earlier ${site.notice ? "lines" : "line"} back, and the tag stays.` : `Revert this pull request, or delete ${lines}.`}
58807
58851
  `;
58808
58852
  }
58809
- var GTM_WHY = "Why: once loaded, the line registers the site's tools for AI agents, and ask_site when the site has it. AI agents never click a cookie banner, so a line held until someone accepts analytics or marketing cookies never loads, and agent visits get no tools. It sets no cookies and writes nothing to local storage. In first-party session storage, cleared when the tab closes, it keeps a random id for the tab (agentface:sid), the number of the visit's next step (agentface:n), the visit's last steps until an AI agent first uses a tool (agentface:steps), and a note that a tool was used (agentface:tool). If session storage is blocked, these are held only in the page's memory and each page counts as a visit of its own. It sends anonymous page-load and tool-use counts under that tab id, with the page's path but not its query string, and the visit's category, which is worked out in the browser. Each page a visit opens is sent as it opens, by its path and the time, so the site owner can compare people's visits with agents'; agentface adds the country and keeps no page title, user agent or lasting id with it. The rest of a visit's steps (clicks, typed fields, questions asked) are sent only for a visit in which an AI agent uses a tool. Of a person's visit, what was clicked and which fields were filled, never what with, is sent only once Google Consent Mode reports analytics_storage as granted. Passwords, payment details, one-time codes and chosen files are never sent: such a field is sent only as hidden. The visitor's IP address is not stored. No sample of the browser's request is kept until Google Consent Mode reports analytics_storage as granted, never while it is denied or unknown, and not on a site with no consent manager. A visitor whose name is marked -User (for example ChatGPT-User) is a classic assistant when they run this line. A crawler that downloads the line's script without running it, fetches the site's tool list or leaves a message, such as GPTBot or ChatGPT-User, is counted as a crawler visit in its own bucket, by the name it sends, with no visit steps. A question a crawler sends to the site's ask address without running the line is kept as a crawler visit with the question, the answer, who asked and when, for 30 days like every question, so the site owner sees every question asked of the site. There is no lasting visitor id today. If one is added, it will be written only once Google Consent Mode reports analytics_storage as granted, never while it is denied or unknown. On these facts it is reasonable to class the line as functional or necessary. The site's consent banner, privacy notice and lawful basis stay the site owner's call. This is information, not legal advice. Everything the line stores and agentface receives: https://agentface.com/docs/snippet-storage";
58810
- var GTM_HOW = `Can't change the site's code? Add the same line in Google Tag Manager instead: Tags > New > Custom HTML, paste it, set the trigger to Initialization - All Pages, then Submit and Publish the container. Under Consent Settings choose No additional consent required: don't make it wait for a Consent Mode signal such as analytics_storage, and don't mark it as an analytics or ads tag. ${GTM_WHY}`;
58853
+ var LOAD_WHY = "Why: once loaded, the line registers the site's tools for AI agents, and ask_site when the site has it. AI agents never click a cookie banner, so a line held until someone accepts analytics or marketing cookies never loads, and agent visits get no tools. It sets no cookies and writes nothing to local storage. In first-party session storage, cleared when the tab closes, it keeps a random id for the tab (agentface:sid), the number of the visit's next step (agentface:n), the visit's last steps until an AI agent first uses a tool (agentface:steps), and a note that a tool was used (agentface:tool). If session storage is blocked, these are held only in the page's memory and each page counts as a visit of its own. It sends anonymous page-load and tool-use counts under that tab id, with the page's path but not its query string, and the visit's category, which is worked out in the browser. Each page a visit opens is sent as it opens, by its path and the time, so the site owner can compare people's visits with agents'; agentface adds the country and keeps no page title, user agent or lasting id with it. The rest of a visit's steps (clicks, typed fields, questions asked) are sent only for a visit in which an AI agent uses a tool. Of a person's visit, what was clicked and which fields were filled, never what with, is sent only once Google Consent Mode reports analytics_storage as granted. Passwords, payment details, one-time codes and chosen files are never sent: such a field is sent only as hidden. The visitor's IP address is not stored. No sample of the browser's request is kept until Google Consent Mode reports analytics_storage as granted, never while it is denied or unknown, and not on a site with no consent manager. A visitor whose name is marked -User (for example ChatGPT-User) is a classic assistant when they run this line. A crawler that downloads the line's script without running it, fetches the site's tool list or leaves a message, such as GPTBot or ChatGPT-User, is counted as a crawler visit in its own bucket, by the name it sends, with no visit steps. A question a crawler sends to the site's ask address without running the line is kept as a crawler visit with the question, the answer, who asked and when, for 30 days like every question, so the site owner sees every question asked of the site. There is no lasting visitor id today. If one is added, it will be written only once Google Consent Mode reports analytics_storage as granted, never while it is denied or unknown. On these facts it is reasonable to class the line as functional or necessary. The site's consent banner, privacy notice and lawful basis stay the site owner's call. This is information, not legal advice. Everything the line stores and agentface receives: https://agentface.com/docs/snippet-storage";
58854
+ var LOAD_HOW = `Load the line on every page as a functional (or necessary) script. Don't wait for cookie consent, and don't put it in a consent-gated analytics or marketing category. ${LOAD_WHY}`;
58811
58855
  var these = (files2) => files2.length === 1 ? "this file" : "these files";
58812
58856
  function noticeByHand(site, noticed, log) {
58813
58857
  if (site.notice && !noticed.some(({ key }) => key === site.id))
@@ -58881,7 +58925,7 @@ function byHand2({ manual, tagged, noticed }, site, service, dryRun, warning, lo
58881
58925
  ${site.tag}
58882
58926
  `
58883
58927
  );
58884
- if (!old.length) log(GTM_HOW);
58928
+ if (!old.length) log(LOAD_HOW);
58885
58929
  noticeByHand(site, noticed, log);
58886
58930
  if (warning) log(warning);
58887
58931
  log(nextSteps(site, service));
@@ -58913,6 +58957,16 @@ function prestaShopSteps(file) {
58913
58957
  return `${what} In the shop's back office, open Modules > Module Manager, click Upload a module and choose ${file}: PrestaShop installs it. ${cache}`;
58914
58958
  return `${what} If this folder is a copy of the shop rather than the live one, first upload the agentface folder to the shop's modules folder there. PrestaShop runs a module only once it's installed: in the shop's back office, open Modules > Module Manager, search for Agentface and click Install. ${cache}`;
58915
58959
  }
58960
+ function wordPressSteps(file) {
58961
+ return `That file is a WordPress plugin of Agentface's own, which puts the tag on every page made from the theme, whatever made its head and body, and which updates of WordPress, its plugins and its theme leave alone. It asks Agentface for the tag and its notice and keeps them an hour, so that when what they say changes, the pages change by themselves, with nothing to run. In the WordPress admin, open Plugins > Add New Plugin, click Upload Plugin, choose ${file} and click Install Now, then Activate Plugin. If the site has a caching plugin, clear its cache, so that the pages show the tag.`;
58962
+ }
58963
+ var wordPressUpload = (id) => ({
58964
+ framework: "WordPress",
58965
+ heads: [],
58966
+ bodies: [],
58967
+ creates: [{ file: `agentface-${id}.zip`, content: wordPressZip }],
58968
+ key: null
58969
+ });
58916
58970
  var PRESTASHOP_THEME = "If this theme isn't yours, such as PrestaShop's own Classic, its next update puts those layouts back without the tag. Run init in the shop's folder instead, the one with config/defines.inc.php: there it adds a module that no update replaces.";
58917
58971
  async function readyForPr(dir, exec) {
58918
58972
  if (await exec("git", ["status", "--porcelain"], { cwd: dir }))
@@ -58938,7 +58992,7 @@ async function init({
58938
58992
  let found = await withFramework(dir, await findHeads(dir));
58939
58993
  if (found.manual && pr)
58940
58994
  throw new Error(
58941
- `${found.manual.reason} --pr only commits what init writes: run init without it to get the tag to add by hand.`
58995
+ `${found.manual.reason} --pr only commits what init writes: run init without it to get ${found.manual.upload ? "the plugin to upload" : "the tag to add by hand"}.`
58942
58996
  );
58943
58997
  if (pr && !dryRun) await readyForPr(dir, exec);
58944
58998
  const site = await siteFor({ id, url, dir, found, service, fetcher, exec, dryRun, log });
@@ -58950,7 +59004,12 @@ async function init({
58950
59004
  framework: "WordPress",
58951
59005
  manual: wordPressManual(`${site.origin}'s homepage comes from WordPress.`)
58952
59006
  };
58953
- else if (found.manual?.none && "html" in homepage && prestaShopPage(homepage.html))
59007
+ let stale = [];
59008
+ if (found.manual?.upload) {
59009
+ log(found.manual.reason);
59010
+ stale = found.tagged.map(({ file }) => file);
59011
+ found = wordPressUpload(site.id);
59012
+ } else if (found.manual?.none && "html" in homepage && prestaShopPage(homepage.html))
58954
59013
  found = {
58955
59014
  framework: "PrestaShop",
58956
59015
  heads: [],
@@ -59011,7 +59070,8 @@ Add a second snippet to All pages, placed in Body \u2013 start:
59011
59070
  const writes = [...after].filter(([file, content]) => content !== before.get(file));
59012
59071
  const files2 = writes.map(([file]) => file);
59013
59072
  const own2 = found.creates.some(({ file }) => file.endsWith(".zip")) ? "plugin" : found.framework === "WordPress" || found.framework === "PrestaShop" ? "file" : void 0;
59014
- const shop = found.framework === "PrestaShop" ? prestaShopSteps(found.creates[0].file) : null;
59073
+ const shop = found.framework === "PrestaShop" ? prestaShopSteps(found.creates[0].file) : found.framework === "WordPress" && own2 === "plugin" ? wordPressSteps(found.creates[0].file) : null;
59074
+ const twice = stale.length ? `${list(stale)} ${stale.length === 1 ? "has" : "have"} an Agentface tag already, from an earlier init or added by hand. Take it out, so that no page loads the tag twice: \`npx agentface uninstall\` does it.` : null;
59015
59075
  const noticed = site.notice && (found.bodies.length || found.creates.length);
59016
59076
  const what = `the Agentface tag${noticed ? " and its notice" : ""}`;
59017
59077
  const had = [...found.heads, ...found.bodies, ...found.creates, ...found.edits ?? []].some(
@@ -59026,6 +59086,7 @@ Add a second snippet to All pages, placed in Body \u2013 start:
59026
59086
  if (found.skipped) log(found.skipped);
59027
59087
  elsewhere();
59028
59088
  if (shop) log(shop);
59089
+ if (twice) log(twice);
59029
59090
  if (warning) log(warning);
59030
59091
  log(nextSteps(site, service, own2));
59031
59092
  return { site, files: files2, written: false };
@@ -59079,8 +59140,9 @@ Add a second snippet to All pages, placed in Body \u2013 start:
59079
59140
  elsewhere();
59080
59141
  if (found.note) log(found.note);
59081
59142
  if (shop) log(shop);
59143
+ if (twice) log(twice);
59082
59144
  if (found.framework === "PrestaShop theme") log(PRESTASHOP_THEME);
59083
- if (found.framework === "WordPress")
59145
+ if (found.framework === "WordPress" && own2 === "file")
59084
59146
  log(
59085
59147
  `WordPress runs that file on every page by itself, as a must-use plugin: there's nothing to activate, and updates of WordPress, its plugins and its theme leave it alone. It asks Agentface for the tag and its notice and keeps them an hour, so that when what they say changes, the pages change by themselves, with nothing to run. If this folder is a copy of the site rather than the live one, upload the file to the same folder there. If the site has a caching plugin, clear its cache, so that the pages show the tag.`
59086
59148
  );
@@ -59141,9 +59203,9 @@ async function check({
59141
59203
  if (!id) {
59142
59204
  const found = await withFramework(dir, await findHeads(dir));
59143
59205
  id = found.key;
59144
- if (!id && found.manual?.steps)
59206
+ if (!id && found.manual?.upload)
59145
59207
  throw new Error(
59146
- "On WordPress the tag isn't in the site's files, so check can't find the site key here. Pass it: npx agentface check --site <site key>. It's in the tag init printed, after /s/."
59208
+ "On WordPress the tag isn't in the site's files, so check can't find the site key here. Pass it: npx agentface check --site <site key>. It's in the check command init printed, and on the site's page in agentface."
59147
59209
  );
59148
59210
  if (!id)
59149
59211
  throw new Error(
@@ -59161,7 +59223,7 @@ async function check({
59161
59223
  );
59162
59224
  return 1;
59163
59225
  }
59164
- const advice2 = tagBlocked(homepage, site, { added: result2.ok });
59226
+ const advice2 = tagBlocked(homepage, site);
59165
59227
  if (result2.ok && advice2) {
59166
59228
  log(
59167
59229
  `Blocked: ${site.origin}'s homepage has the tag for ${id}, but the site's Content Security Policy, the list of hosts its pages may use, doesn't let them ${advice2.effect}. ${advice2.fixes}`
@@ -59204,7 +59266,7 @@ async function uninstall({
59204
59266
  const plugin = await isWordPress(dir) && await wordPressFile(dir);
59205
59267
  if (plugin !== false && !tagged.some(({ file }) => file === plugin))
59206
59268
  log(
59207
- "On WordPress, take the Agentface tag and its notice out of the plugin's boxes for the head and the body, where init said to paste them, and save: in WPCode, that's Code Snippets > Header & Footer."
59269
+ "On WordPress, open Plugins in the WordPress admin, then deactivate and delete Agentface. If the tag and its notice were pasted into another plugin's boxes for the head and the body instead, such as WPCode's, take them out there and save."
59208
59270
  );
59209
59271
  const undone = await undoFrameworks(dir);
59210
59272
  if (!tagged.length && !undone.edits.length && !undone.deletes.length) {