agentface 0.3.0 → 0.5.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 +219 -48
  2. package/package.json +1 -1
@@ -5,7 +5,7 @@ import { parseArgs } from "node:util";
5
5
 
6
6
  // cli/init.mjs
7
7
  import { execFile as execFile2 } from "node:child_process";
8
- import { mkdir, readFile as readFile2, writeFile } from "node:fs/promises";
8
+ import { mkdir, readFile as readFile2, rm, writeFile } from "node:fs/promises";
9
9
  import path2 from "node:path";
10
10
 
11
11
  // worker/origin.js
@@ -31,6 +31,15 @@ function registrableOrigin(input) {
31
31
  return origin;
32
32
  }
33
33
 
34
+ // worker/tag.js
35
+ var toolListUrl = (serviceOrigin, id) => `${serviceOrigin}/s/${id}.md`;
36
+ function siteTag(serviceOrigin, id) {
37
+ return `<script async src="${serviceOrigin}/s/${id}.js" data-ai-agents="Tools for AI agents on this site: ${toolListUrl(serviceOrigin, id)}"></script>`;
38
+ }
39
+ function siteNotice(serviceOrigin, id) {
40
+ return `<noscript>This site has tools for AI agents, which run in its pages in a browser: ${toolListUrl(serviceOrigin, id)}</noscript>`;
41
+ }
42
+
34
43
  // cli/heads.mjs
35
44
  import { execFile } from "node:child_process";
36
45
  import { readdir, readFile, stat } from "node:fs/promises";
@@ -114,17 +123,23 @@ var exists = (file) => stat(file).then(
114
123
  );
115
124
  var KEY = /\/s\/(site-[a-z0-9-]+)\.js(?=[?#"'`\s]|$)/;
116
125
  var TAG = new RegExp(`<script\\b[^>]*?${KEY.source}[^>]*?(?:\\/>|>\\s*<\\/script\\s*>)`, "gi");
126
+ var NOTICE = /<noscript\b[^>]*>[^<]*\/s\/(site-[a-z0-9-]+)\.md[^<]*<\/noscript\s*>/i;
127
+ var BODY = /<body(?=[\s>/])(?:<\?[\s\S]*?\?>|<%[\s\S]*?%>|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}|"[^"]*"|'[^']*'|[^>])*>/i;
128
+ var onItsLine = (pattern) => new RegExp(`(\\r?\\n[ \\t]*)?${pattern.source}`, "gi");
117
129
  var OURS = "Added by `npx agentface init`";
118
130
  function tagKey(source) {
119
131
  return source.match(KEY)?.[1] ?? null;
120
132
  }
133
+ function noticeKey(source) {
134
+ return source.match(NOTICE)?.[1] ?? null;
135
+ }
121
136
  function indentUnit(source) {
122
137
  return source.match(/^(\t| {2,4})\S/m)?.[1] ?? " ";
123
138
  }
124
139
  var indentOf = (line) => line.match(/^[ \t]*/)[0];
125
140
  function addTag(source, tag) {
126
141
  let first = true;
127
- const replaced = source.replace(new RegExp(`(\\r?\\n[ \\t]*)?${TAG.source}`, "gi"), (match, line) => {
142
+ const replaced = source.replace(onItsLine(TAG), (match, line) => {
128
143
  if (!first) return "";
129
144
  first = false;
130
145
  return (line ?? "") + tag;
@@ -151,6 +166,24 @@ function addTag(source, tag) {
151
166
  const lines = [`${child}<head>`, `${child}${step}${tag}`, `${child}</head>`];
152
167
  return source.slice(0, end) + eol + lines.join(eol) + source.slice(end);
153
168
  }
169
+ function addNotice(source, notice) {
170
+ let first = true;
171
+ const replaced = source.replace(onItsLine(NOTICE), (match, line) => {
172
+ if (!first) return "";
173
+ first = false;
174
+ return (line ?? "") + notice;
175
+ });
176
+ if (!first) return replaced;
177
+ const body = BODY.exec(source);
178
+ if (!body) return null;
179
+ const end = body.index + body[0].length;
180
+ const next = source.slice(end).match(/^[ \t]*\r?\n([ \t]*)(.*)/);
181
+ if (!next) return source.slice(0, end) + notice + source.slice(end);
182
+ const eol = source.includes("\r\n") ? "\r\n" : "\n";
183
+ const outer = indentOf(source.slice(source.lastIndexOf("\n", body.index) + 1));
184
+ const indent = next[2].trim() && !/^<\/body\b/i.test(next[2]) ? next[1] : outer + indentUnit(source);
185
+ return source.slice(0, end) + eol + indent + notice + source.slice(end);
186
+ }
154
187
  function gitFiles(dir) {
155
188
  return new Promise((resolve) => {
156
189
  execFile(
@@ -193,7 +226,7 @@ async function siteGenerator(dir) {
193
226
  return "Jekyll";
194
227
  return null;
195
228
  }
196
- var NEXT_DOCUMENT = (tag) => `// ${OURS}: Next.js's own document, plus the Agentface tag.
229
+ var NEXT_DOCUMENT = (tag, notice) => `// ${OURS}: Next.js's own document, plus the Agentface tag.
197
230
  import { Html, Head, Main, NextScript } from 'next/document';
198
231
 
199
232
  export default function Document() {
@@ -203,43 +236,95 @@ export default function Document() {
203
236
  ${tag}
204
237
  </Head>
205
238
  <body>
206
- <Main />
239
+ ${notice ? ` ${notice}
240
+ ` : ""} <Main />
207
241
  <NextScript />
208
242
  </body>
209
243
  </Html>
210
244
  );
211
245
  }
212
246
  `;
213
- var GATSBY_SSR = (tag) => {
247
+ var GATSBY_SSR = (tag, notice) => {
214
248
  const src = tag.match(/\bsrc="([^"]+)"/)[1];
249
+ const about = tag.match(/\bdata-ai-agents="([^"]+)"/)?.[1];
250
+ const text = notice?.match(/>([^<]*)</)[1];
251
+ const props = `key: 'agentface', async: true, src: '${src}'${about ? `, 'data-ai-agents': '${about}'` : ""}`;
215
252
  return `// ${OURS}: puts the Agentface tag in every page's <head>.
216
253
  const React = require('react');
217
254
 
218
- exports.onRenderBody = ({ setHeadComponents }) => {
255
+ exports.onRenderBody = ({ setHeadComponents${text ? ", setPreBodyComponents" : ""} }) => {
219
256
  setHeadComponents([
220
- React.createElement('script', { key: 'agentface', async: true, src: '${src}' }),
257
+ React.createElement('script', { ${props} }),
221
258
  ]);
222
- };
259
+ ${text ? ` setPreBodyComponents([React.createElement('noscript', { key: 'agentface' }, '${text}')]);
260
+ ` : ""}};
223
261
  `;
224
262
  };
263
+ async function project(dir) {
264
+ const pkg = JSON.parse(await read(path.join(dir, "package.json")) ?? "null");
265
+ const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
266
+ const generator = await siteGenerator(dir);
267
+ const skip = new Set(SKIP);
268
+ if (generator === "Hugo") for (const name of ["public", "resources", "themes"]) skip.add(name);
269
+ if (deps.gatsby) skip.add("public");
270
+ const framework = FRAMEWORKS.find(([dependency]) => deps[dependency])?.[1] ?? generator ?? (pkg ? "JavaScript" : "HTML");
271
+ const { files: list2, git } = await files(dir, skip);
272
+ return { deps, framework, list: list2, git };
273
+ }
274
+ async function findTags(dir) {
275
+ const { list: list2 } = await project(dir);
276
+ const tagged = [];
277
+ for (const file of list2) {
278
+ const source = await contents(dir, file);
279
+ const key = source === null ? null : tagKey(source) ?? noticeKey(source);
280
+ if (key) tagged.push({ file, source, key });
281
+ }
282
+ return tagged;
283
+ }
284
+ function madeByInit(source) {
285
+ const src = source.match(/['"](https?:\/\/[^'"\s]+)['"]/)?.[1];
286
+ const [, origin, id] = src?.match(/^(.+)\/s\/(site-[a-z0-9-]+)\.js$/) ?? [];
287
+ if (!origin) return false;
288
+ const made = [
289
+ [`<script async src="${src}"></script>`, null],
290
+ [siteTag(origin, id), siteNotice(origin, id)]
291
+ ];
292
+ return made.some(
293
+ ([tag, notice]) => [NEXT_DOCUMENT, GATSBY_SSR].some((write) => source === write(tag, notice))
294
+ );
295
+ }
296
+ function removeTag(source) {
297
+ if (source.includes(OURS) && madeByInit(source)) return null;
298
+ return [TAG, NOTICE].reduce(
299
+ (text, pattern) => text.replace(onItsLine(pattern), (match, line, ...rest) => {
300
+ const after = rest.at(-1).slice(rest.at(-2) + match.length);
301
+ return line && !/^[ \t]*(?:\r?\n|$)/.test(after) ? line : "";
302
+ }),
303
+ source
304
+ );
305
+ }
225
306
  async function byHand(dir, list2, framework, reason, how) {
226
307
  const tagged = [];
308
+ const noticed = [];
227
309
  for (const file of list2) {
228
310
  const text = await contents(dir, file);
229
311
  const key = text === null ? null : tagKey(text);
230
312
  if (key) tagged.push({ file, key });
313
+ if (text !== null && noticeKey(text)) noticed.push(noticeKey(text));
231
314
  }
232
- return { framework, heads: [], creates: [], manual: { reason, how }, tagged, key: tagged[0]?.key ?? null };
315
+ return {
316
+ framework,
317
+ heads: [],
318
+ bodies: [],
319
+ creates: [],
320
+ manual: { reason, how },
321
+ tagged,
322
+ noticed,
323
+ key: tagged[0]?.key ?? null
324
+ };
233
325
  }
234
326
  async function findHeads(dir) {
235
- const pkg = JSON.parse(await read(path.join(dir, "package.json")) ?? "null");
236
- const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
237
- const generator = await siteGenerator(dir);
238
- const skip = new Set(SKIP);
239
- if (generator === "Hugo") for (const name of ["public", "resources", "themes"]) skip.add(name);
240
- if (deps.gatsby) skip.add("public");
241
- const framework = FRAMEWORKS.find(([dependency]) => deps[dependency])?.[1] ?? generator ?? (pkg ? "JavaScript" : "HTML");
242
- const { files: list2, git } = await files(dir, skip);
327
+ const { deps, framework, list: list2, git } = await project(dir);
243
328
  for (const [dependency, [name, where]] of Object.entries(CONFIG_HEAD))
244
329
  if (deps[dependency])
245
330
  return byHand(
@@ -250,6 +335,7 @@ async function findHeads(dir) {
250
335
  `Add it by hand through ${where}, with this tag's src`
251
336
  );
252
337
  const heads = [];
338
+ const bodies = [];
253
339
  for (const file of list2) {
254
340
  const markup = MARKUP.test(file);
255
341
  if (!markup && !LAYOUTS.some((layout) => layout.test(file)) || MAIL.test(path.posix.basename(file)))
@@ -258,6 +344,7 @@ async function findHeads(dir) {
258
344
  if (text === null) continue;
259
345
  const head = markup ? /<\/head\s*>/i.test(text) : /<\/head\s*>|<html\b/i.test(text);
260
346
  if (head) heads.push({ file, source: text });
347
+ if (BODY.test(text)) bodies.push({ file, source: text });
261
348
  }
262
349
  const creates = [];
263
350
  if (deps.next && !heads.some(({ file }) => /(?:^|\/)app\//.test(file))) {
@@ -291,7 +378,7 @@ async function findHeads(dir) {
291
378
  "Add this line by hand, last in the <head> of the layout or template every page uses"
292
379
  );
293
380
  const sources = [...heads.map(({ source }) => source), ...creates.map(({ source }) => source ?? "")];
294
- return { framework, heads, creates, key: sources.map(tagKey).find(Boolean) ?? null };
381
+ return { framework, heads, bodies, creates, key: sources.map(tagKey).find(Boolean) ?? null };
295
382
  }
296
383
 
297
384
  // cli/init.mjs
@@ -320,7 +407,7 @@ async function lookupSite(service, id, fetcher = fetch) {
320
407
  { unknownSite: true }
321
408
  );
322
409
  if (!response.ok) throw new Error(body?.message ?? `Agentface answered HTTP ${response.status}`);
323
- return { ...body.site, tag: body.tag };
410
+ return { ...body.site, tag: body.tag, notice: body.notice ?? null };
324
411
  }
325
412
  async function register(service, url, fetcher = fetch) {
326
413
  const { response, body } = await reach(
@@ -331,7 +418,7 @@ async function register(service, url, fetcher = fetch) {
331
418
  );
332
419
  if (!response.ok || !body?.site?.id)
333
420
  throw new Error(body?.message ?? `Agentface could not register ${url} (HTTP ${response.status})`);
334
- return { ...body.site, expiresAt: body.expiresAt, tag: body.tag };
421
+ return { ...body.site, expiresAt: body.expiresAt, tag: body.tag, notice: body.notice ?? null };
335
422
  }
336
423
  async function confirm(service, id, fetcher = fetch) {
337
424
  const { response, body } = await reach(
@@ -381,26 +468,47 @@ function run(command, args, { cwd }) {
381
468
  });
382
469
  });
383
470
  }
471
+ var bare = (origin) => origin.replace(/^https:\/\/www\./, "https://");
472
+ var sameSite = (a, b) => bare(a) === bare(b);
384
473
  async function siteFor({ id, url, dir, found, service, fetcher, exec, dryRun, log }) {
385
- if (id) return lookupSite(service, id, fetcher);
474
+ let origin;
475
+ if (url) {
476
+ try {
477
+ origin = registrableOrigin(url);
478
+ } catch (error) {
479
+ throw new Error(`Can't register ${url}. ${error.message}.`, { cause: error });
480
+ }
481
+ }
482
+ if (id) {
483
+ const site2 = await lookupSite(service, id, fetcher);
484
+ if (origin && !sameSite(site2.origin, origin))
485
+ throw new Error(
486
+ `${id} is the site for ${site2.origin}, not ${origin}. Leave out the key to register ${origin}.`
487
+ );
488
+ return site2;
489
+ }
386
490
  if (found.key) {
387
491
  try {
388
- return await lookupSite(service, found.key, fetcher);
492
+ const site2 = await lookupSite(service, found.key, fetcher);
493
+ if (!origin || sameSite(site2.origin, origin)) return site2;
494
+ log(
495
+ `This project's tag names ${found.key}, the site for ${site2.origin}. Registering ${origin} instead, as --url asks.`
496
+ );
389
497
  } catch (error) {
390
498
  if (!error.unknownSite) throw error;
391
499
  log(
392
- `Agentface no longer has ${found.key}, the site this project's tag names (an unconfirmed site is deleted after a day). Registering it again.`
500
+ `Agentface no longer has ${found.key}, the site this project's tag names (an unconfirmed site is deleted after a week). Registering it again.`
393
501
  );
394
502
  }
395
503
  }
396
- if (!url) {
504
+ if (!origin) {
397
505
  const address = await siteUrl(dir, exec);
398
506
  if (!address)
399
507
  throw new Error(
400
508
  "Which site is this? Run this again with its address: npx agentface init --url https://example.com"
401
509
  );
402
510
  try {
403
- registrableOrigin(address.url);
511
+ origin = registrableOrigin(address.url);
404
512
  } catch (error) {
405
513
  throw new Error(
406
514
  `This project's address, ${address.url} (from ${address.from}), can't be registered. ${error.message}. If the site is served from another address, pass it with --url.`,
@@ -408,20 +516,14 @@ async function siteFor({ id, url, dir, found, service, fetcher, exec, dryRun, lo
408
516
  );
409
517
  }
410
518
  log(`Using ${address.url} (from ${address.from}). For another address, pass --url.`);
411
- url = address.url;
412
- }
413
- let origin;
414
- try {
415
- origin = registrableOrigin(url);
416
- } catch (error) {
417
- throw new Error(`Can't register ${url}. ${error.message}.`, { cause: error });
418
519
  }
419
520
  if (dryRun) {
420
521
  log(`Would register ${origin} with Agentface.`);
421
522
  return {
422
523
  id: "site-new",
423
524
  origin,
424
- tag: `<script async src="${service}/s/site-new.js"></script>`
525
+ tag: siteTag(service, "site-new"),
526
+ notice: siteNotice(service, "site-new")
425
527
  };
426
528
  }
427
529
  const site = await register(service, origin + "/", fetcher);
@@ -436,21 +538,32 @@ function nextSteps(site, service) {
436
538
  }
437
539
  function prBody(site, files2, service = DEFAULT_SERVICE) {
438
540
  const src = site.tag.match(/\bsrc="([^"]+)"/)?.[1];
541
+ const notice = site.notice ? ` A \`<noscript>\` line first in the body links agents that read pages without running them, and so never get the tools, to a list of them. Browsers that run scripts don't show it.` : "";
439
542
  return `Adds the Agentface tag to ${site.origin}, so AI agents that use the site in a browser get tools made for them.
440
543
 
441
- **What it does.** One \`<script async>\` line in ${files2.map((file) => `\`${file}\``).join(", ")} loads ${src} on every page. It gives browser agents tools for this site (read a page as Markdown, search the site, fill in forms, close pop-ups) and reports how agents use them: which tools, how long they took and their error codes, never what anyone typed or read. People visiting the site see no change, and it sets no cookies.
544
+ **What it does.** It changes ${files2.map((file) => `\`${file}\``).join(", ")}. One \`<script async>\` line in the head loads ${src} on every page. It gives browser agents tools for this site (read a page as Markdown, search the site, fill in forms, close pop-ups) and reports how agents use them: which tools, how long they took and their error codes, never what anyone typed or read.${notice} People visiting the site see no change, and it sets no cookies.
442
545
 
443
546
  **Check it.** ${nextSteps(site, service)}
444
547
 
445
- **Uninstall.** Revert this pull request, or delete the line.
548
+ **Uninstall.** Revert this pull request, or delete ${site.notice ? "the two lines" : "the line"}.
446
549
  `;
447
550
  }
448
- function byHand2({ manual, tagged }, site, service, dryRun, log) {
551
+ function noticeByHand(site, noticed, log) {
552
+ if (site.notice && !noticed.includes(site.id))
553
+ log(
554
+ `For agents that read pages without running them, also add this line first in the <body> of every page:
555
+
556
+ ${site.notice}
557
+ `
558
+ );
559
+ }
560
+ function byHand2({ manual, tagged, noticed }, site, service, dryRun, log) {
449
561
  const current = tagged.filter(({ key }) => key === site.id).map(({ file }) => file);
450
562
  if (current.length) {
451
563
  log(
452
564
  `${list(current)} already ${current.length === 1 ? "has" : "have"} the Agentface tag for ${site.id}.`
453
565
  );
566
+ noticeByHand(site, noticed, log);
454
567
  log(nextSteps(site, service));
455
568
  return { site, files: [], written: false };
456
569
  }
@@ -466,6 +579,7 @@ function byHand2({ manual, tagged }, site, service, dryRun, log) {
466
579
  ${site.tag}
467
580
  `
468
581
  );
582
+ noticeByHand(site, noticed, log);
469
583
  log(nextSteps(site, service));
470
584
  return { site, files: [], written: false };
471
585
  }
@@ -497,26 +611,33 @@ async function init({
497
611
  if (pr && !dryRun) await readyForPr(dir, exec);
498
612
  const site = await siteFor({ id, url, dir, found, service, fetcher, exec, dryRun, log });
499
613
  if (found.manual) return byHand2(found, site, service, dryRun, log);
500
- const writes = [];
614
+ const before = /* @__PURE__ */ new Map();
615
+ const after = /* @__PURE__ */ new Map();
501
616
  for (const { file, source } of found.heads) {
502
- const content = addTag(source, site.tag);
503
- if (content !== source) writes.push([file, content]);
617
+ before.set(file, source);
618
+ after.set(file, addTag(source, site.tag));
504
619
  }
620
+ if (site.notice)
621
+ for (const { file, source } of found.bodies) {
622
+ before.set(file, source);
623
+ after.set(file, addNotice(after.get(file) ?? source, site.notice) ?? after.get(file) ?? source);
624
+ }
505
625
  for (const { file, content, source } of found.creates) {
506
- const made = content(site.tag);
507
- if (made !== source) writes.push([file, made]);
626
+ before.set(file, source);
627
+ after.set(file, content(site.tag, site.notice));
508
628
  }
629
+ const writes = [...after].filter(([file, content]) => content !== before.get(file));
509
630
  const files2 = writes.map(([file]) => file);
510
- const where = list([...found.heads.map(({ file }) => file), ...found.creates.map(({ file }) => file)]);
631
+ const noticed = site.notice && (found.bodies.length || found.creates.length);
632
+ const what = `the Agentface tag${noticed ? " and its notice" : ""}`;
511
633
  if (!writes.length) {
512
- log(
513
- `${where} already ${found.heads.length + found.creates.length === 1 ? "has" : "have"} the Agentface tag for ${site.id}.`
514
- );
634
+ const tagged = [...found.heads, ...found.creates].map(({ file }) => file);
635
+ log(`${list(tagged)} already ${tagged.length === 1 ? "has" : "have"} the Agentface tag for ${site.id}.`);
515
636
  log(nextSteps(site, service));
516
637
  return { site, files: files2, written: false };
517
638
  }
518
639
  if (dryRun) {
519
- log(`Would add the Agentface tag to ${list(files2)} (${found.framework}) for ${site.origin}.`);
640
+ log(`Would add ${what} to ${list(files2)} (${found.framework}) for ${site.origin}.`);
520
641
  return { site, files: files2, written: false };
521
642
  }
522
643
  let returnTo;
@@ -528,7 +649,7 @@ async function init({
528
649
  await mkdir(path2.dirname(path2.join(dir, file)), { recursive: true });
529
650
  await writeFile(path2.join(dir, file), content);
530
651
  }
531
- log(`Added the Agentface tag to ${list(files2)} (${found.framework}) for ${site.origin}.`);
652
+ log(`Added ${what} to ${list(files2)} (${found.framework}) for ${site.origin}.`);
532
653
  if (!pr) {
533
654
  log(nextSteps(site, service));
534
655
  return { site, files: files2, written: true };
@@ -595,6 +716,50 @@ async function check({
595
716
  log(`Until it's confirmed, Agentface deletes ${id} at ${when(site.expiresAt)}.`);
596
717
  return 1;
597
718
  }
719
+ async function uninstall({
720
+ dir = process.cwd(),
721
+ service = DEFAULT_SERVICE,
722
+ dryRun = false,
723
+ fetch: fetcher = fetch,
724
+ log = console.log
725
+ }) {
726
+ const tagged = await findTags(dir);
727
+ if (!tagged.length) {
728
+ log("No Agentface tag in this project.");
729
+ return { files: [], deleted: [], byHand: [] };
730
+ }
731
+ const edits = [];
732
+ const deleted = [];
733
+ const byHand3 = [];
734
+ for (const { file, source } of tagged) {
735
+ const content = removeTag(source);
736
+ if (content === null) deleted.push(file);
737
+ else if (tagKey(content)) byHand3.push(file);
738
+ else edits.push([file, content]);
739
+ }
740
+ const files2 = edits.map(([file]) => file);
741
+ if (!dryRun) {
742
+ for (const [file, content] of edits) await writeFile(path2.join(dir, file), content);
743
+ for (const file of deleted) await rm(path2.join(dir, file));
744
+ }
745
+ const would = (done, undone) => dryRun ? undone : done;
746
+ if (files2.length) log(`${would("Removed", "Would remove")} the Agentface tag from ${list(files2)}.`);
747
+ if (deleted.length)
748
+ log(`${would("Deleted", "Would delete")} ${list(deleted)}, which init made for the tag.`);
749
+ if (byHand3.length)
750
+ log(
751
+ `${list(byHand3)} ${byHand3.length === 1 ? "loads" : "load"} the Agentface script some other way, such as from config: remove it there by hand.`
752
+ );
753
+ if (dryRun) return { files: files2, deleted, byHand: byHand3 };
754
+ log("Deploy it as usual: once the tag is off the site, nothing loads Agentface.");
755
+ for (const key of new Set(tagged.map(({ key: key2 }) => key2))) {
756
+ const site = await lookupSite(service, key, fetcher).catch(() => null);
757
+ if (site?.expiresAt)
758
+ log(`${key} was never confirmed, so Agentface deletes it at ${when(site.expiresAt)}.`);
759
+ else if (site) log(`${key} stays registered for ${site.origin}; \`npx agentface init\` puts it back.`);
760
+ }
761
+ return { files: files2, deleted, byHand: byHand3 };
762
+ }
598
763
 
599
764
  // cli/agentface.mjs
600
765
  var HELP = `Usage:
@@ -602,11 +767,12 @@ var HELP = `Usage:
602
767
  folder. Without a site key, registers the site first.
603
768
  agentface check Check that the deployed homepage has the tag. The first
604
769
  time, that confirms the site is yours.
770
+ agentface uninstall Remove the Agentface tag from this folder's pages.
605
771
 
606
772
  Options:
607
773
  --url The site's address, like https://example.com (init finds it when it can)
608
774
  --site check: the site key (check finds it in the project when it can)
609
- --pr Commit the change on a new branch and open a pull request (needs git and gh)
775
+ --pr init: commit the change on a new branch and open a pull request (needs git and gh)
610
776
  --dry-run Show what would change, without registering or writing anything
611
777
  --service Agentface service URL (default ${DEFAULT_SERVICE})`;
612
778
  async function main(argv, { log = console.log, dir = process.cwd(), fetch: fetcher = fetch } = {}) {
@@ -641,6 +807,11 @@ async function main(argv, { log = console.log, dir = process.cwd(), fetch: fetch
641
807
  });
642
808
  return 0;
643
809
  }
810
+ if (command === "uninstall") {
811
+ if (values.pr) throw new Error("--pr works with init only: commit the change yourself.");
812
+ await uninstall({ dir, service, dryRun: values["dry-run"], fetch: fetcher, log });
813
+ return 0;
814
+ }
644
815
  if (command === "check") return check({ site: values.site ?? arg, dir, service, fetch: fetcher, log });
645
816
  throw new Error(`Unknown command "${command}".
646
817
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentface",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Add the Agentface tag to a website's pages, so AI agents get tools made for it.",
5
5
  "bin": {
6
6
  "agentface": "dist/agentface.mjs"