domain-hound 0.1.1 → 0.1.3

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.
@@ -2,17 +2,19 @@ import { execFile } from 'node:child_process';
2
2
  import { setTimeout as delay } from 'node:timers/promises';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import { promisify } from 'node:util';
5
- import { confirmDomain, confirmingShops } from './confirm.mjs';
5
+ import { apiShops, cachedSignals, confirmDomain, confirmingShops, lightConfirm } from './confirm.mjs';
6
6
  import { appStoreSearchLink, googleSearchLink, nameCheckLines, playSearchLink } from './google-search.mjs';
7
- import { eligibilityNotes, mergeQuote, nameCandidates, normalizeName, pickName, rankName, registrationStatus,
8
- searchCandidates, searchName, termCosts, validEligibility, validEndings } from './name-search.mjs';
7
+ import { asciiDomain, canRecommend, defaultEndings, eligibilityNotes, listQuote, mergeQuote, nameCandidates, normalizeName, pickName,
8
+ premiumRisk, rankName, registrationStatus, searchCandidates, searchName, termCosts, unicodeName, validEligibility, validEndings,
9
+ withPremiumRisk, withoutListPrice } from './name-search.mjs';
9
10
  import { bundledCatalog, catalogOffers, datedListPrices, isListPriceUsable, loadCachedCatalog, refreshPrices } from './price-catalog.mjs';
10
11
  import { lookupRegistrations } from './registry.mjs';
11
- import { namingRecipe } from './naming-method.mjs';
12
+ import { namingRecipe, purchaseLine } from './naming-method.mjs';
13
+ import { progressReporter } from './progress.mjs';
12
14
  import { namePresence, triageNames } from './triage.mjs';
13
15
  import { refreshTranco } from './traction.mjs';
14
16
  import {
15
- catalogPrice, dynadotOffer, money, offer, porkbunOffer, rankedFirstYear, shops, shopSearchUrl, threeYearCost, transferStrategy, vatNorway,
17
+ catalogPrice, dynadotOffer, linkable, money, offer, porkbunOffer, rankedFirstYear, shops, shopSearchUrl, threeYearCost, transferStrategy, vatNorway,
16
18
  } from './prices.mjs';
17
19
 
18
20
  const runFile = promisify(execFile);
@@ -22,7 +24,7 @@ const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/5
22
24
  const porkbun = 'https://api.porkbun.com/api/json/v3/';
23
25
  const nokUrl = 'https://data.norges-bank.no/api/data/EXR/B.USD.NOK.SP?lastNObservations=1&format=sdmx-json';
24
26
  const shopHosts = new Set([
25
- 'spaceship.com', 'www.spaceship.com', 'porkbun.com', 'namecheap.com', 'www.namecheap.com',
27
+ 'spaceship.com', 'www.spaceship.com', 'namecheap.com', 'www.namecheap.com',
26
28
  'dynadot.com', 'www.dynadot.com', 'domains.cloudflare.com', 'dash.cloudflare.com', 'www.cloudflare.com',
27
29
  'www.namesilo.com', 'shop.gandi.net', 'www.ionos.com', 'www.hover.com',
28
30
  'euipo.europa.eu', 'tmsearch.uspto.gov', 'www.godaddy.com', 'domains.squarespace.com', 'www.hostinger.com',
@@ -64,10 +66,12 @@ async function openShop(args) {
64
66
  }
65
67
 
66
68
  export function normalize(input) {
67
- const domain = typeof input === 'string' ? input.trim().toLowerCase()
69
+ const typed = typeof input === 'string' ? input.trim().toLowerCase()
68
70
  .replace(/^[a-z][a-z\d+.-]*:\/\//, '')
69
71
  .split(/[/?#]/, 1)[0]
70
72
  .replace(/^www\.(?=[^.]+\.)/, '') : '';
73
+ // A Unicode domain is checked as its punycode form, never with letters removed.
74
+ const domain = asciiDomain(typed) ?? '';
71
75
  const labels = domain.split('.');
72
76
  const label = /^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/;
73
77
  const tld = /^(?:[a-z]{2,63}|xn--[a-z\d](?:[a-z\d-]{0,57}[a-z\d])?)$/;
@@ -174,7 +178,7 @@ export async function checkDomain(input, {
174
178
  const tld = domain.split('.').at(-1);
175
179
  const deadline = performance.now() + totalTimeout;
176
180
  const timeout = () => Math.max(0, Math.min(maxTimeout, Math.floor(deadline - performance.now())));
177
- const [registrations, catalog, pricing, dynadot, confirmed, nok] = await Promise.all([
181
+ const [registrations, catalog, pricing, dynadot, confirmed, nok, signals] = await Promise.all([
178
182
  lookupRegistrations([{ domain, tld }], { fetcher, directory, queryWhois, now,
179
183
  timeLeft: timeout, dnsFirst: false, readExpiry: true }),
180
184
  loadCachedCatalog(directory),
@@ -182,10 +186,40 @@ export async function checkDomain(input, {
182
186
  loadDynadot(tld, fetcher, timeout()),
183
187
  liveConfirmation(domain, env, fetcher, timeout()),
184
188
  loadNok(fetcher, timeout()),
189
+ cachedSignals([domain], { directory, now }),
185
190
  ]);
186
191
  const registry = registrations[0];
187
- const verdict = confirmed ? 'confirmed' : registry.status;
192
+ const listFor = (_domain, shop) => datedListPrices(catalog, tld, now, bundled).find(row => row.id === shop) ?? null;
193
+ const shopQuote = registry.status === 'taken' ? null : signals.get(domain)
194
+ ?? (await lightConfirm([domain], { env, fetcher, directory, now, deadline: performance.now() + timeout(), listFor })).get(domain) ?? null;
195
+ // Porkbun's own quote above its list price, without a premium flag, may still be premium.
196
+ const porkbunList = pricing?.pricing?.[tld] ? catalogPrice(pricing.pricing[tld].registration) : null;
197
+ const porkbunPremium = confirmed && (confirmed.premium || (porkbunList != null && confirmed.price > porkbunList + 0.01));
198
+ // A short name may be premium: no list price unless a shop marks its quote as standard.
199
+ const risk = registry.status === 'free' && premiumRisk(domain) && shopQuote?.standard !== true && !porkbunPremium;
200
+ const premium = registry.signal === 'premium' || shopQuote?.status === 'premium' || porkbunPremium || risk;
201
+ const reserved = registry.signal === 'reserved' || shopQuote?.status === 'reserved';
202
+ const verdict = shopQuote?.status === 'taken' || registry.status === 'taken' ? 'taken'
203
+ : reserved ? 'reserved' : premium ? 'premium' : confirmed || shopQuote?.status === 'confirmed' ? 'confirmed' : registry.status;
188
204
  const offers = [];
205
+ if (verdict === 'premium' || verdict === 'reserved') {
206
+ // A premium or reserved name is never shown at list price.
207
+ const quoted = shopQuote?.price != null && shopQuote.status === 'premium' ? shopQuote : null;
208
+ const shopId = quoted?.shop ?? (tld === 'no' ? 'dynadot' : 'spaceship');
209
+ const best = quoted ? { ...offer(shopId, domain, { firstYear: quoted.price, regularFirstYear: quoted.price,
210
+ renewal: quoted.renewal, evidence: 'shop', source: 'api', checkedAt: quoted.checkedAt }),
211
+ premium: quoted.premium, label: 'confirmed at ' + shops[shopId].name + ' ' + quoteTime(quoted.checkedAt) } : null;
212
+ return {
213
+ domain, confirmShop: shopId, confirmShopName: shops[shopId].name, checkedAt: now.toISOString(), verdict, registry,
214
+ confirmed: confirmed ? { ...confirmed, ...(!confirmed.premium && { possible: true }) } : null,
215
+ ...(shopQuote && { shopQuote }), best, cheapestToday: null, offers: best ? [best] : [], stale: false,
216
+ priceDate: null, nok, vatNorway,
217
+ ...(risk && !quoted && { premiumRisk: true }),
218
+ notes: [registry.reason, reserved ? 'Not offered for registration; check at the shop'
219
+ : best ? null : risk && !registry.signal ? 'May be premium, price at shop' : 'Premium, price at shop'].filter(Boolean),
220
+ buyUrl: shopSearchUrl(shopId, domain),
221
+ };
222
+ }
189
223
  if (verdict !== 'taken') {
190
224
  // Live shop prices replace a saved or bundled list price from the same shop.
191
225
  const priced = [...catalogOffers(catalog, tld, domain, datedListPrices(catalog, tld, now, bundled)),
@@ -195,6 +229,12 @@ export async function checkDomain(input, {
195
229
  const row = byShop.get(name) ?? offer(id, domain, {
196
230
  firstYear: null, regularFirstYear: null, renewal: null, checkedAt: null, source: null,
197
231
  });
232
+ if (shopQuote?.status === 'confirmed' && name === shopQuote.shopName) {
233
+ Object.assign(row, { firstYear: shopQuote.price, regularFirstYear: shopQuote.price, code: null, codeNote: null,
234
+ renewal: shopQuote.renewal, source: 'api', checkedAt: shopQuote.checkedAt,
235
+ label: 'confirmed at ' + name + ' ' + quoteTime(shopQuote.checkedAt) });
236
+ row.threeYear = threeYearCost(row);
237
+ }
198
238
  if (name === confirmed?.by && !confirmed.premium) {
199
239
  row.regularFirstYear = confirmed.price;
200
240
  if (!row.code || row.firstYear >= confirmed.price) {
@@ -205,18 +245,22 @@ export async function checkDomain(input, {
205
245
  offers.push(row);
206
246
  }
207
247
  offers.sort((a, b) => cost(rankedFirstYear(a)) - cost(rankedFirstYear(b)) || cost(a.renewal) - cost(b.renewal));
248
+ for (const row of offers) row.label ??= row.firstYear == null ? null : 'list price';
208
249
  }
209
- const best = offers.find(row => rankedFirstYear(row) != null) ?? null;
210
- const today = offers.reduce((lowest, row) => cost(rankedFirstYear(row)) < cost(rankedFirstYear(lowest ?? {})) ? row : lowest, best);
250
+ // Data-only shops stay in offers as evidence but are never the pick or the cheapest link.
251
+ const picks = offers.filter(row => !row.dataOnly);
252
+ const best = picks.find(row => rankedFirstYear(row) != null) ?? null;
253
+ const today = picks.reduce((lowest, row) => cost(rankedFirstYear(row)) < cost(rankedFirstYear(lowest ?? {})) ? row : lowest, best);
211
254
  const priceDate = best?.checkedAt?.slice(0, 10) ?? null;
212
255
  const stale = !best || !isListPriceUsable(best.checkedAt, now);
213
256
  const transfer = !stale && !confirmed?.premium && oneYearTransfer.has(tld)
214
- ? transferStrategy(offers.filter(row => isListPriceUsable(row.checkedAt, now))) : null;
215
- const confirmingOffer = offers.find(row => rankedFirstYear(row) != null && confirmingShops.includes(shopIds.get(row.shop)));
257
+ ? transferStrategy(picks.filter(row => isListPriceUsable(row.checkedAt, now))) : null;
258
+ const confirmingOffer = picks.find(row => rankedFirstYear(row) != null && confirmingShops.includes(shopIds.get(row.shop)));
216
259
  const confirmShop = shopIds.get(confirmingOffer?.shop)
217
260
  ?? (tld === 'no' ? 'dynadot' : tld === 'so' ? 'namecheap' : 'spaceship');
218
261
  return {
219
- domain, confirmShop, confirmShopName: shops[confirmShop].name, checkedAt: now.toISOString(), verdict, registry, confirmed, best,
262
+ domain, confirmShop, confirmShopName: shops[confirmShop].name, checkedAt: now.toISOString(), verdict, registry, confirmed,
263
+ ...(shopQuote && { shopQuote }), best,
220
264
  cheapestToday: today === best ? null : today,
221
265
  ...(transfer && { transfer }),
222
266
  offers, stale, priceDate, nok, vatNorway,
@@ -226,9 +270,16 @@ export async function checkDomain(input, {
226
270
 
227
271
  const shopIds = new Map(Object.entries(shops).map(([id, { name }]) => [name, id]));
228
272
 
273
+ // "12:04 UTC" for a shop quote.
274
+ function quoteTime(value) {
275
+ const time = typeof value === 'string' ? value.match(/T(\d{2}:\d{2})/)?.[1] : null;
276
+ return time ? time + ' UTC' : '';
277
+ }
278
+
229
279
  const agentLegend = {
230
- nc: 'Free, not confirmed',
231
- ok: 'Free, confirmed by a shop',
280
+ nc: 'Free at the registry; list price, not confirmed',
281
+ ok: 'Free, price confirmed at the shop (at = quote time)',
282
+ prem: 'Premium: price at the shop, never a list price',
232
283
  resale: 'Taken, possible resale',
233
284
  shop_check: 'Registry did not settle; check at a shop',
234
285
  d: 'Ending, or full domain for a name variant',
@@ -237,6 +288,9 @@ const agentLegend = {
237
288
  y3: 'Payments due in three years, USD ex. VAT',
238
289
  term: 'Years per payment when more than one',
239
290
  jump: 'Renewal over twice the first annual price',
291
+ risk: 'Short name: may be premium, price at the shop',
292
+ likely_free: 'Registry silent, DNS has no delegation: likely free, confirm at a shop',
293
+ likely_taken: 'Registry silent, DNS has a delegation: likely taken',
240
294
  };
241
295
  const googleEndings = new Set(['app', 'dev']);
242
296
  // Playwright is optional. Without it (or its browser) the live shop check cannot run at all.
@@ -267,7 +321,11 @@ function agentPrice({ firstPayment: now, renewalPayment: renew, threeYear: y3, m
267
321
  ...(minimumYears > 1 && { term: minimumYears }), ...(renewalJump && { jump: true }), ...(shop && { shop }) };
268
322
  }
269
323
 
270
- function compactAgentResult(groups, names, complete, checkedAt, batch, rateLimited = false, liveCheck = null) {
324
+ // The shop quote time as HH:MM UTC.
325
+ const quoteClock = value => typeof value === 'string' ? value.match(/T(\d{2}:\d{2})/)?.[1] ?? null : null;
326
+
327
+ function compactAgentResult(groups, names, complete, checkedAt, batch, rateLimited = false, liveCheck = null,
328
+ { eligible, otherEndings } = {}) {
271
329
  const buyUrlTemplate = {};
272
330
  const shopCheckWhy = {};
273
331
  const listPrices = {};
@@ -276,18 +334,22 @@ function compactAgentResult(groups, names, complete, checkedAt, batch, rateLimit
276
334
  let priceListDate;
277
335
  let best;
278
336
  for (const { name, results } of groups) {
279
- const taken = [], resale = [], free = [], shop_check = [];
337
+ const taken = [], resale = [], free = [], shop_check = [], likelyFree = [], likelyTaken = [];
280
338
  for (const row of results) {
281
339
  checkedEndings.add(row.tld);
282
340
  const d = row.exact ? row.tld : row.domain;
283
341
  const shop = row.shop ?? shops[row.confirmShop]?.name;
284
- const confirmed = row.status === 'confirmed';
342
+ const premium = row.status === 'premium';
343
+ const confirmed = row.status === 'confirmed' || (premium && row.price != null && row.source === 'shop');
285
344
  const price = agentPrice({ ...row, shop });
286
- if (batch && !confirmed && row.status !== 'premium' && listPrices[d]?.now == null) {
345
+ // A taken exact domain can show a standard ending benchmark. For .ai this explains its two-year renewal.
346
+ const benchmark = !batch && row.exact && row.status === 'taken' && row.listPrice
347
+ && (row.tld === 'ai' || !premiumRisk(row.domain));
348
+ if ((batch || benchmark) && !confirmed && !premium && row.status !== 'reserved' && listPrices[d]?.now == null) {
287
349
  const listed = row.listPrice ? agentPrice(row.listPrice) : price;
288
350
  if (Object.keys(listed).length) listPrices[d] = listed;
289
351
  }
290
- const date = (row.priceCheckedAt ?? (batch ? row.listPrice?.checkedAt : null))?.slice(0, 10);
352
+ const date = (row.priceCheckedAt ?? (batch || benchmark ? row.listPrice?.checkedAt : null))?.slice(0, 10);
291
353
  // Use the oldest list date among the displayed estimates.
292
354
  if (date && (priceListDate === undefined || date < priceListDate)) priceListDate = date;
293
355
  if (row.status === 'taken') {
@@ -295,44 +357,65 @@ function compactAgentResult(groups, names, complete, checkedAt, batch, rateLimit
295
357
  continue;
296
358
  }
297
359
  const shopId = shopIds.get(shop);
298
- if (shopId) {
360
+ if (shopId && linkable(shopId)) {
299
361
  const { url, suffix = '' } = shops[shopId];
300
362
  buyUrlTemplate[shop] = url + '{domain}' + suffix;
301
363
  }
364
+ if (premium && !confirmed) {
365
+ // Premium without a price: free to register, but only the shop shows the price. A short name may be premium.
366
+ free.push({ d, s: 'prem', ...(shop && { shop }), ...(row.premium === 'risk' && { risk: true }) });
367
+ continue;
368
+ }
369
+ if (row.status === 'reserved') {
370
+ shop_check.push(d);
371
+ shopCheckWhy[row.domain] = String(row.registryReason ?? 'Not offered for registration').slice(0, 80);
372
+ continue;
373
+ }
302
374
  if (!confirmed && row.status !== 'probably-free') {
303
375
  if (!batch && row.status === 'check-at-shop' && price.now != null) listPrices[d] = price;
304
376
  shop_check.push(d);
305
377
  shopCheckWhy[d] ??= shopCheckReason(row, rateLimited);
378
+ if (row.likely === 'free') likelyFree.push(d);
379
+ if (row.likely === 'taken') likelyTaken.push(d);
306
380
  continue;
307
381
  }
308
382
  // A batch row repeats its ending's standard price only when it differs.
309
383
  const standard = batch && !confirmed && listPrices[d] && JSON.stringify(listPrices[d]) === JSON.stringify(price);
310
- free.push({ d, s: confirmed ? 'ok' : 'nc', ...(!standard && price) });
311
- if (confirmed) {
384
+ const at = confirmed ? quoteClock(row.quotedAt ?? row.checkedAt) : null;
385
+ free.push({ d, s: confirmed ? 'ok' : 'nc', ...(!standard && price), ...(premium && { prem: row.premium ?? true }),
386
+ ...(at && { at }) });
387
+ if (confirmed && !premium && canRecommend(row.tld, eligible) && !premiumRisk(row.domain)) {
312
388
  const { now, renew, y3, term, jump } = price;
313
389
  const buyUrl = row.buyUrl ?? shopSearchUrl(shopId, row.domain);
314
- best = { domain: row.domain, status: 'free-confirmed', ...(now != null && { priceNow: now }),
390
+ // The cheapest confirmed quote is the pick; rows are already sorted by first payment within a name.
391
+ if (best && (best.priceNow ?? Infinity) <= (now ?? Infinity)) continue;
392
+ best = { domain: row.domain, status: 'free-confirmed', ...(now != null && { priceNow: now }), ...(at && { at }),
315
393
  ...(renew != null && { renewal: renew }), ...(y3 != null && { threeYear: y3 }),
316
394
  ...(term && { term }),
317
395
  ...(jump && { renewalNote: 'Renews at $' + renew.toFixed(2) }),
318
396
  ...(shop && { shop }), ...(buyUrl && { buyUrl }) };
319
397
  }
320
398
  }
321
- byName.set(name, { name, ...(taken.length && { taken }), ...(resale.length && { resale }),
322
- ...(free.length && { free }), ...(shop_check.length && { shop_check }) });
399
+ const unicode = unicodeName(name);
400
+ byName.set(name, { name, ...(unicode && { unicode }), ...(taken.length && { taken }), ...(resale.length && { resale }),
401
+ ...(free.length && { free }), ...(shop_check.length && { shop_check }),
402
+ // Subsets of shop_check with a DNS likelihood; only a registry or shop settles them.
403
+ ...(likelyFree.length && { likely_free: likelyFree }), ...(likelyTaken.length && { likely_taken: likelyTaken }) });
323
404
  }
324
405
  const result = {
406
+ ...(!batch && names[0].includes('.') && {
407
+ purchaseAdvice: 'For a purchase request, include this sentence even when the domain is taken: ' + purchaseLine,
408
+ }),
325
409
  complete, checkedAt, ...(priceListDate && { priceListDate }), ...(best && { best }),
326
410
  eligibility: eligibilityNotes([...checkedEndings]),
411
+ ...(eligible?.length && { eligible }),
327
412
  names: names.map(name => byName.get(name)),
328
- ...(!batch && names[0].includes('.') && {
329
- purchaseAdvice: 'If the person asked to buy, say Domain Hound cannot buy domains, even if the domain is taken.',
330
- }),
331
413
  legend: agentLegend,
332
414
  ...(Object.keys(buyUrlTemplate).length && { buyUrlTemplate }),
333
415
  ...(Object.keys(shopCheckWhy).length && { shopCheckWhy }),
334
416
  // The registry and list-price evidence above stays; this only says the shop quote could not be checked.
335
417
  ...(liveCheck && !best && { liveCheck }),
418
+ ...(otherEndings && Object.keys(otherEndings).length && { otherEndings }),
336
419
  };
337
420
  if (Object.keys(listPrices).length) {
338
421
  result.listPrices = listPrices;
@@ -347,11 +430,21 @@ function compactAgentResult(groups, names, complete, checkedAt, batch, rateLimit
347
430
  return result;
348
431
  }
349
432
 
433
+ // The top pick and up to three runners-up get a light confirm: registry signals first, then a keyed shop API.
434
+ export function lightTargets(rows, eligible, count = 4) {
435
+ const top = pickName(rows, eligible);
436
+ const others = rankName(rows.filter(row => row !== top && ['probably-free', 'premium'].includes(row.status)
437
+ && canRecommend(row.tld, eligible)));
438
+ return [top, ...others].filter(Boolean).slice(0, count);
439
+ }
440
+
350
441
  export async function agentResult(input, options = {}) {
351
- // Leave room under the 15-second wall clock limit for Node startup and browser cleanup.
352
- const deadline = performance.now() + (options.budgetMs ?? 13_900);
353
- const remaining = () => Math.max(0, Math.floor(deadline - performance.now()));
354
442
  const batch = Array.isArray(input);
443
+ // The default path has no browser and answers a single name or a small batch within 8 seconds.
444
+ // Larger batches and the explicit browser check keep room under the 15-second wall clock limit.
445
+ const small = !batch || input.length <= 3;
446
+ const deadline = performance.now() + (options.budgetMs ?? (options.browser || !small ? 13_900 : 7_400));
447
+ const remaining = () => Math.max(0, Math.floor(deadline - performance.now()));
355
448
  if (batch && (!input.length || input.length > 20)) return { error: 'Provide 1 to 20 names.' };
356
449
  if (options.endings && !validEndings(options.endings)) return { error: 'Choose supported domain endings.' };
357
450
  if (options.eligible !== undefined && !validEligibility(options.eligible)) return { error: 'Eligible endings must list supported restricted endings, such as no.' };
@@ -364,19 +457,40 @@ export async function agentResult(input, options = {}) {
364
457
  const exact = new Set(domain ? [domain] : names.filter((name, index) => batch && exactDomain(input[index])));
365
458
  const groups = [...new Set(names)].map(name => ({ name, candidates: exact.has(name)
366
459
  ? [{ domain: name, tld: name.split('.').at(-1), exact: true }] : nameCandidates(name, { ...options, variants: !batch }) }));
367
- const searchOptions = { ...options, budgetMs: Math.min(remaining(), batch ? 10_700 : 2700),
460
+ const keyed = apiShops(options.env ?? process.env).length > 0;
461
+ const reserve = keyed ? 1800 : 0;
462
+ const searchOptions = { ...options, budgetMs: Math.max(0, Math.min(remaining() - reserve, batch ? 10_700 : 2700)),
368
463
  skipComSite: batch || options.skipComSite };
369
464
  const fast = await searchCandidates(groups, searchOptions);
370
465
  let rateLimited = fast.groups.some(group => group.results.some(row =>
371
466
  googleEndings.has(row.tld) && /HTTP 429/.test(row.registryReason ?? '')));
372
467
  if (batch) rateLimited = await retryGoogle(fast, remaining, options) || rateLimited;
373
468
  const rows = fast.groups.flatMap(group => group.results);
374
- const candidate = domain ? rows.find(row => row.status === 'probably-free' || row.status === 'check-at-shop')
375
- : pickName(rankName(rows), options.eligible);
469
+ const targets = domain ? rows.filter(row => canRecommend(row.tld, options.eligible)
470
+ && ['probably-free', 'check-at-shop', 'premium'].includes(row.status))
471
+ : lightTargets(rows, options.eligible);
472
+ const [candidate] = targets;
376
473
  // A Google retry can settle every row that the first pass left waiting.
377
474
  let complete = fast.complete || !rows.some(row => row.registryReason === 'Registry lookup timed out');
475
+ const quotes = new Map();
476
+ if (targets.length) {
477
+ options.onProgress?.({ stage: 'quotes' });
478
+ const catalog = await loadCachedCatalog(options.directory);
479
+ const listFor = (target, shop) => datedListPrices(catalog, target.split('.').at(-1), options.now ?? new Date(),
480
+ options.bundledCatalog === undefined ? bundledCatalog : options.bundledCatalog).find(row => row.id === shop) ?? null;
481
+ const light = options.lightConfirm ?? lightConfirm;
482
+ const found = await light(targets.map(row => row.domain), { env: options.env, fetcher: options.fetcher,
483
+ directory: options.directory, now: options.now, deadline: performance.now() + Math.max(0, remaining() - 150), listFor })
484
+ .catch(() => new Map());
485
+ for (const [key, value] of found) quotes.set(key, value);
486
+ }
378
487
  let quote;
379
- if (candidate && remaining() >= 1000) {
488
+ const firstQuote = candidate && quotes.get(candidate.domain);
489
+ const fallback = options.browser && candidate && (!firstQuote || firstQuote.status === 'could-not-confirm'
490
+ || firstQuote.status === 'premium' && firstQuote.price == null);
491
+ if (fallback && remaining() >= 1000) {
492
+ // The headless browser runs only when the person explicitly asks for it.
493
+ options.onProgress?.({ stage: 'browser' });
380
494
  const confirm = options.confirm ?? confirmDomain;
381
495
  let timer;
382
496
  try {
@@ -389,13 +503,39 @@ export async function agentResult(input, options = {}) {
389
503
  } finally {
390
504
  clearTimeout(timer);
391
505
  }
392
- } else if (candidate) {
506
+ if (quote && quote.status !== 'could-not-confirm') {
507
+ quotes.set(candidate.domain, firstQuote?.status === 'premium' && quote.available === true
508
+ ? { ...quote, status: 'premium', premium: firstQuote.premium } : quote);
509
+ }
510
+ } else if (fallback) {
393
511
  complete = false;
394
512
  }
395
- const apply = row => row.domain === candidate?.domain ? mergeQuote(row, quote) : row;
513
+ const apply = row => quotes.has(row.domain) ? mergeQuote(row, quotes.get(row.domain)) : row;
396
514
  const rankedGroups = fast.groups.map(({ name, results }) => ({ name, results: rankName(results.map(apply)) }));
397
515
  const checkedAt = options.now?.toISOString() ?? new Date().toISOString();
398
- return compactAgentResult(rankedGroups, names, complete, checkedAt, batch, rateLimited, liveCheckFor(candidate, quote));
516
+ // An exact .com gets the standard list prices of the other endings as one benchmark line, with no extra lookups.
517
+ const exactCom = names.length === 1 && names[0].endsWith('.com') ? names[0] : null;
518
+ const otherEndings = exactCom ? await endingBenchmarks(exactCom, options) : null;
519
+ return compactAgentResult(rankedGroups, names, complete, checkedAt, batch, rateLimited,
520
+ options.browser ? liveCheckFor(candidate, quote) : null, { eligible: options.eligible, otherEndings });
521
+ }
522
+
523
+ // The cheapest standard list price of each other ending for this label, from the saved or bundled price list.
524
+ // A short label may be premium, so it gets no benchmark.
525
+ async function endingBenchmarks(domain, options) {
526
+ const label = domain.slice(0, domain.indexOf('.'));
527
+ if (premiumRisk(label)) return null;
528
+ const now = options.now ?? new Date();
529
+ const bundled = options.bundledCatalog === undefined ? bundledCatalog : options.bundledCatalog;
530
+ const catalog = await loadCachedCatalog(options.directory).catch(() => null);
531
+ const prices = {};
532
+ for (const tld of defaultEndings.filter(ending => ending !== 'com' && canRecommend(ending, options.eligible))) {
533
+ const quote = listQuote(catalog, { domain: label + '.' + tld, tld }, now, bundled);
534
+ if (quote.price == null) continue;
535
+ const costs = termCosts(tld, quote.price, quote.renewal);
536
+ prices[tld] = agentPrice({ ...costs, renewalJump: quote.renewal > 2 * quote.price, shop: quote.shop });
537
+ }
538
+ return prices;
399
539
  }
400
540
 
401
541
  // Give unresolved .app and .dev rows one bounded registry retry with the batch time that is left.
@@ -430,11 +570,14 @@ async function retryGoogle(fast, remaining, options) {
430
570
  const status = registrationStatus(answer);
431
571
  if (status === 'check-at-shop') {
432
572
  if (/HTTP 429/.test(answer.reason ?? '')) limited = true;
433
- return { ...row, registryReason: answer.reason ?? row.registryReason };
573
+ return { ...row, registryReason: answer.reason ?? row.registryReason, ...(answer.likely && { likely: answer.likely }) };
434
574
  }
435
- const settled = { ...row, status, source: answer.source, registryReason: undefined, forSale: Boolean(answer.forSale),
575
+ const { likely, ...open } = row;
576
+ const settled = { ...open, status, source: answer.source, registryReason: undefined, forSale: Boolean(answer.forSale),
436
577
  checkedAt: answer.checkedAt ?? (options.now ?? new Date()).toISOString() };
437
- if (status !== 'taken') return settled;
578
+ if (status === 'premium') return { ...withoutListPrice(settled, status), premium: true };
579
+ if (status === 'reserved') return withoutListPrice(settled, status, answer.reason);
580
+ if (status !== 'taken') return withPremiumRisk(settled);
438
581
  const { price, renewal, shop, priceCheckedAt } = row;
439
582
  for (const key of ['price', 'renewal', 'shop', 'priceSource', 'priceCheckedAt', 'buyUrl']) delete settled[key];
440
583
  return price == null ? settled : { ...settled, listPrice: { shop, checkedAt: priceCheckedAt,
@@ -454,14 +597,16 @@ function workflowAgent(input) {
454
597
  let value;
455
598
  try { value = JSON.parse(input); } catch { return { error: 'Provide a query or a list of names.' }; }
456
599
  if (!value || typeof value !== 'object' ||
457
- Object.keys(value).some(key => !['query', 'names', 'endings', 'ai', 'eligible'].includes(key)) ||
600
+ Object.keys(value).some(key => !['query', 'names', 'endings', 'ai', 'eligible', 'confirm'].includes(key)) ||
601
+ (Object.hasOwn(value, 'confirm') && typeof value.confirm !== 'boolean') ||
458
602
  Object.hasOwn(value, 'query') === Object.hasOwn(value, 'names') ||
459
603
  !(typeof value.query === 'string' || Array.isArray(value.names)) ||
460
604
  (Object.hasOwn(value, 'ai') && typeof value.ai !== 'boolean') ||
461
605
  (Object.hasOwn(value, 'endings') && !validEndings(value.endings))) {
462
606
  return { error: 'Provide either a query or a list of names.' };
463
607
  }
464
- return agentResult(value.query ?? value.names, value);
608
+ const { confirm, ...rest } = value;
609
+ return agentResult(value.query ?? value.names, { ...rest, browser: confirm === true });
465
610
  }
466
611
 
467
612
  // Per-name GEO from the calling agent's own recollection: {"Name":"known: what it is"|"unknown"}.
@@ -484,6 +629,8 @@ function lookupArgs(args) {
484
629
  else if (arg === '--eligible' && !options.eligible) options.eligible = (args[++index] ?? '').split(',');
485
630
  else if (arg === '--category' && !options.category) options.category = (args[++index] ?? '').slice(0, 100);
486
631
  else if (arg === '--compact') options.compact = true;
632
+ // The headless browser shop check runs only on this explicit flag.
633
+ else if (arg === '--confirm') options.browser = true;
487
634
  else if (arg === '--geo' && options.geo === undefined) options.geo = readGeo(args[++index]);
488
635
  else if (arg === '--about' && options.about === undefined) options.about = (args[++index] ?? '').slice(0, 160);
489
636
  else positional.push(arg);
@@ -498,6 +645,9 @@ function runConfirmation(shop, domain) {
498
645
  if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
499
646
  const args = process.argv.slice(2);
500
647
  const { options, positional } = lookupArgs(args.slice(1));
648
+ // The MCP server reads these to answer with progress when a lookup outlasts its budget.
649
+ const onProgress = progressReporter();
650
+ if (onProgress) options.onProgress = onProgress;
501
651
  const refreshDir = process.env.DOMAIN_HOUND_PRICE_CACHE;
502
652
  if (args[0] === '--naming-method' && !positional.length) {
503
653
  console.log(namingRecipe(options.about));
@@ -506,8 +656,8 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
506
656
  : args[0] === '--agent' ? await agentArgs(positional, options)
507
657
  : args[0] === '--agent-input' && args.length === 2 ? await workflowAgent(args[1])
508
658
  : args[0] === '--confirm' ? await runConfirmation(args[1], args.length === 3 ? normalize(args[2]) : null)
509
- : args[0] === '--refresh-prices' && args.length === 1
510
- ? await refreshPrices({ directory: refreshDir ? pathToFileURL(refreshDir) : undefined })
659
+ : args[0] === '--refresh-prices' && (args.length === 1 || args.length === 2 && args[1] === '--confirm')
660
+ ? await refreshPrices({ directory: refreshDir ? pathToFileURL(refreshDir) : undefined, browser: args.length === 2 })
511
661
  : args[0] === '--naming-method' ? { error: 'Use --naming-method with an optional --about "product description".' }
512
662
  : args[0] === '--name' ? positional.length > 1 || /\s/.test(positional[0] ?? '')
513
663
  ? { error: 'Use --name with one domain label. For a multiword product name, run --naming-method.' }