domain-hound 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/results.mjs CHANGED
@@ -4,7 +4,8 @@ import { mkdir, readdir, rename, stat, unlink, writeFile } from 'node:fs/promise
4
4
  import { homedir, userInfo } from 'node:os';
5
5
  import { join, resolve } from 'node:path';
6
6
  import { pathToFileURL } from 'node:url';
7
- import { canRecommend, defaultEndings, normalizeName } from './clis/domain-check/name-search.mjs';
7
+ import { canRecommend, defaultEndings, domainEnding, eligibilityNeed, normalizeName } from './clis/domain-check/name-search.mjs';
8
+ import { handlePriorities, handleStates, handleSummary } from './clis/domain-check/handles.mjs';
8
9
  import { shopSearchUrl, shops } from './clis/domain-check/prices.mjs';
9
10
  import { safeLink } from './display.mjs';
10
11
  import { receiptStyle } from './results-style.mjs';
@@ -17,7 +18,6 @@ const evidenceText = value => plain(value).replace(/\[([^\]]*)\]\([^)]*\)/g, '$1
17
18
  .replace(/https?:\/\/[^\s)]+/gi, '').replace(/[\[\]<>]/g, '').replace(/\s{2,}/g, ' ').trim();
18
19
  const markdown = value => plain(value).replace(/[\\|<>\[\]`*]/g, '\\$&');
19
20
  const shopIds = new Map(Object.entries(shops).map(([id, { name }]) => [name, id]));
20
- const endingOf = value => value.split('.').at(-1);
21
21
  const fallbackShop = ending => ending === 'no' ? 'dynadot' : ending === 'so' ? 'namecheap' : 'spaceship';
22
22
  const markOf = row => row.competition?.US;
23
23
  const marksText = row => {
@@ -27,16 +27,19 @@ const marksText = row => {
27
27
  const watchLink = domain => 'https://domainhound.dev/watch/?domain=' + encodeURIComponent(domain);
28
28
  const verdictOrder = { 'No conflict found': 0, 'Check first': 1, Avoid: 2 };
29
29
 
30
- function resultGroups(data) {
30
+ function resultGroups(data, eligibleEndings) {
31
31
  return data.names.map((row, index) => {
32
32
  const detail = data.receiptDetails?.[index] ?? {};
33
33
  const exact = row.name.includes('.');
34
34
  const label = exact ? row.name : normalizeName(row.name);
35
- const variants = [...(row.free ?? []), ...(row.taken ?? []), ...(row.shop_check ?? []), ...(row.resale ?? [])]
36
- .map(value => value.d ?? value).filter(value => value.includes('.'));
37
- const targets = exact ? [row.name] : [...new Set([...defaultEndings.map(ending => label + '.' + ending), ...variants])];
35
+ const listed = [...(row.free ?? []), ...(row.taken ?? []), ...(row.shop_check ?? []), ...(row.resale ?? []),
36
+ ...(row.premium ?? []), ...(row.reserved ?? [])].map(value => value.d ?? value).filter(value => typeof value === 'string');
37
+ const variants = listed.filter(value => value.includes('.') && value !== 'co.uk');
38
+ // Endings on request (such as .de or .uk) join the default endings when the lookup returned them.
39
+ const extra = listed.filter(value => (!value.includes('.') || value === 'co.uk') && !defaultEndings.includes(value));
40
+ const targets = exact ? [row.name] : [...new Set([...[...defaultEndings, ...extra].map(ending => label + '.' + ending), ...variants])];
38
41
  const records = targets.map(domain => {
39
- const ending = endingOf(domain);
42
+ const ending = domainEnding(domain);
40
43
  const lookupKey = domain === label + '.' + ending || exact ? ending : domain;
41
44
  const match = list => list?.find(value => (value.d ?? value) === domain || (value.d ?? value) === lookupKey);
42
45
  const option = match(row.free);
@@ -54,7 +57,8 @@ function resultGroups(data) {
54
57
  const status = taken ? (match(row.resale) ? 'Taken, possible resale' : 'Taken')
55
58
  : reserved ? 'Not offered for registration' : confirmed ? 'Confirmed at shop'
56
59
  : premium ? (risk ? 'May be premium, price at shop' : 'Premium, price at shop')
57
- : option ? 'Free at the registry' : likely ? 'Check at shop, ' + likely : 'Check at shop';
60
+ : option ? 'Free at the registry' : likely ? 'Check at shop, ' + likely
61
+ : data.pending && !match(row.shop_check) ? 'Still checking' : 'Check at shop';
58
62
  const usd = includePrice ? { now: quote.now, renew: quote.renew, y3: quote.y3, term: quote.term,
59
63
  jump: quote.jump, shop: quote.shop } : {};
60
64
  const term = usd.term ?? 1;
@@ -62,12 +66,12 @@ function resultGroups(data) {
62
66
  const source = ({ web: 'Live site', dns: 'DNS', rdap: 'Registry RDAP', whois: 'Registry WHOIS',
63
67
  shop: 'Shop', list: 'Price list' })[raw?.source] ?? (confirmed ? 'Shop' : likely ? 'DNS' : 'Registry');
64
68
  const shop = usd.shop ?? raw?.shop ?? shops[fallbackShop(ending)]?.name;
65
- const eligible = canRecommend(ending, data.eligible);
69
+ const eligible = canRecommend(ending, eligibleEndings ?? data.eligible);
66
70
  const shopUrl = shopSearchUrl(shopIds.get(shop) ?? fallbackShop(ending), domain);
67
71
  const checkout = taken || reserved || !eligible ? null : [raw?.checkout, shopUrl].find(url => safeLink(url, domain)) ?? null;
68
72
  return { domain, ending, state, status, ...usd, total, shop, checkout, eligible, source,
69
73
  priceLabel: usd.now != null || usd.renew != null ? (confirmed ? 'Shop quote' : taken ? 'Standard list price benchmark' : 'List price') : '',
70
- checkedAt: raw?.checkedAt ?? data.checkedAt, priceAt: raw?.priceAt ?? option?.at ?? data.priceListDate,
74
+ checkedAt: raw?.checkedAt ?? data.checkedAt, priceAt: confirmed ? raw?.checkedAt ?? data.checkedAt : raw?.priceAt ?? data.priceListDate,
71
75
  site: raw?.site ?? detail.details?.sites?.[ending] ?? row.details?.sites?.[ending] };
72
76
  });
73
77
  records.sort((a, b) => Number(b.state === 'free' || b.priceLabel === 'Shop quote')
@@ -76,13 +80,17 @@ function resultGroups(data) {
76
80
  });
77
81
  }
78
82
 
83
+ function priceDate(offer) {
84
+ return offer.priceAt ? ' checked ' + offer.priceAt.slice(0, 10) : '';
85
+ }
86
+
79
87
  function offerText(offer, linked = false) {
80
88
  const { domain, checkout, now, renew, term, jump, priceLabel } = offer;
81
89
  const price = now != null ? cash(now) + (renew != null ? ', then ' + cash(renew) : ', renewal at shop')
82
90
  : renew != null ? cash(renew) + ' renewal' : 'price at shop';
83
91
  return (linked && checkout ? '[' + domain + '](' + checkout + ')' : domain) + ' ' + price
84
92
  + (term > 1 ? ' every ' + term + ' years' : '') + (jump ? ' (renewal jumps)' : '')
85
- + (priceLabel ? ' ' + priceLabel.toLowerCase() : '');
93
+ + (priceLabel ? ' ' + priceLabel.toLowerCase() + priceDate(offer) : '');
86
94
  }
87
95
 
88
96
  function appFinding(value) {
@@ -133,7 +141,7 @@ function summary(groups, args, triage) {
133
141
  let price = hasPrice ? ' ' + offerText(picked).slice(picked.domain.length + 1) + '.' : '';
134
142
  if (picked.state === 'taken' && picked.renew != null) {
135
143
  price = ' Standard list renewal: ' + cash(picked.renew) + (picked.term > 1
136
- ? ' every ' + picked.term + ' years (' + cash(picked.renew / picked.term) + ' a year)' : ' a year') + '.';
144
+ ? ' every ' + picked.term + ' years (' + cash(picked.renew / picked.term) + ' a year)' : ' a year') + priceDate(picked) + '.';
137
145
  }
138
146
  const overBudget = budget != null && picked.now != null && picked.now > budget && picked.state !== 'taken';
139
147
  const intro = picked.domain + ': ' + picked.status.toLowerCase() + '.' + price + (overBudget ? ' Over budget.' : '');
@@ -159,13 +167,18 @@ function summary(groups, args, triage) {
159
167
  const eligibility = args.eligible?.includes('no') || cheapest?.record.ending === 'no'
160
168
  || value?.record.ending === 'no' || preferred.includes('no')
161
169
  ? ' .no needs a Norwegian address and organization or personal ID.' : '';
170
+ const waiting = Array.isArray(wanted.row.handles) && wanted.row.handles.filter(row => row.why === 'still checking').map(row => row.platform);
171
+ const handles = !triage ? null : waiting?.length
172
+ ? 'still checking ' + waiting.join(', ') + '. Check links on the page'
173
+ : handleSummary(wanted.row.handles, { ordered: true });
162
174
  const lines = [
163
175
  leadPick || (scope ? scope + 'All endings are on the page.' : null),
164
176
  keep,
177
+ handles && 'Handles for ' + evidenceText(wanted.row.name) + ': ' + plain(handles) + '.',
165
178
  ...offerLines,
166
179
  'Cheapest: ' + (cheapest ? label(cheapest) : 'none found in scope.'),
167
180
  'Best value: ' + (value ? value.record.domain + ', ' + cash(value.record.total) + ' in payments due in 3 years'
168
- + caution(value) : 'needs a shop quote') + '.',
181
+ + ' (' + value.record.priceLabel.toLowerCase() + priceDate(value.record) + ')' + caution(value) : 'needs a shop quote') + '.',
169
182
  (args.purchase ? 'Domain Hound cannot buy or complete checkout. ' : '') + next + eligibility,
170
183
  ];
171
184
  return lines.filter(Boolean);
@@ -208,6 +221,46 @@ function details(group) {
208
221
  return matches.filter(([text, href]) => text && (href || !/ search$/.test(text)));
209
222
  }
210
223
 
224
+ // One line per platform in display order: Taken, No public profile found or Check yourself, with the profile link.
225
+ function handleLines(group) {
226
+ const rows = Array.isArray(group.row.handles) ? group.row.handles : [];
227
+ return rows.flatMap(row => {
228
+ const label = row.platform + ' @' + plain(row.handle) + ': ' + (handleStates[row.state] ?? handleStates.check);
229
+ const detail = row.why === 'still checking' ? ' · still checking' : row.checkedAt ? ' · checked ' + plain(row.checkedAt) : '';
230
+ return [[label + detail, httpsLink(row.link)], ...(row.variants ?? []).map(variant => [
231
+ row.platform + ' alternative @' + plain(variant.handle) + ': ' + (handleStates[variant.state] ?? handleStates.check),
232
+ httpsLink(variant.link),
233
+ ])];
234
+ });
235
+ }
236
+
237
+ function nameSnapshot({ row, records }) {
238
+ const mark = row.competition?.US;
239
+ const apps = [row.competition?.AppStore, row.competition?.GooglePlay];
240
+ const open = records.filter(record => record.state === 'free' && record.eligible).length;
241
+ const blocked = records.filter(record => record.state === 'taken').length;
242
+ const handles = Array.isArray(row.handles) ? row.handles : [];
243
+ const taken = handles.filter(handle => handle.state === 'taken').length;
244
+ const absent = handles.filter(handle => handle.state === 'not-found').length;
245
+ const checks = handles.filter(handle => handle.state === 'check').length;
246
+ return [
247
+ 'Domains ' + open + ' open' + (blocked ? ', ' + blocked + ' taken' : ''),
248
+ 'Trademark ' + (mark == null ? 'check incomplete' : mark.length ? 'match found' : 'no US match'),
249
+ 'Apps ' + (apps.some(value => value?.length) ? 'same-name listing' : apps.some(value => value == null) ? 'check incomplete' : 'no match'),
250
+ 'Handles ' + (handles.length ? [taken ? taken + ' taken' : null,
251
+ absent + taken ? absent + ' of ' + (absent + taken) + ' with no public match' : null, checks ? checks + ' to check' : null].filter(Boolean).join(', ')
252
+ : 'outside top three'),
253
+ ].join(' / ');
254
+ }
255
+
256
+ function handlePriority({ row }, companyType) {
257
+ if (!Array.isArray(row.handles) || !row.handles.length || !Object.hasOwn(handlePriorities, companyType)) return '';
258
+ return 'Handles to secure for this business: ' + handlePriorities[companyType].map(platform => {
259
+ const entry = row.handles.find(handle => handle.platform === platform);
260
+ return platform + ' ' + (entry?.why === 'still checking' ? 'still checking' : handleStates[entry?.state ?? 'check'].toLowerCase());
261
+ }).join(', ') + '.';
262
+ }
263
+
211
264
  const anchor = (label, url) => '<a href="' + escape(url) + '">' + escape(label) + '</a>';
212
265
  function summaryHtml(line) {
213
266
  return Array.from(line.matchAll(/\[([^\]]+)\]\((https:\/\/[^\s)]+)\)/g)).reduce(({ html, offset }, match) =>
@@ -222,11 +275,11 @@ const amountsFor = ({ now, renew }) => [cash(now) ?? 'No price', cash(renew) ??
222
275
 
223
276
  function rowNote(row) {
224
277
  return [row.status, row.priceLabel, row.term > 1 ? row.term + ' years per payment' : null,
225
- row.jump ? 'Renewal jumps' : null, !row.eligible ? '.no buyer eligibility required' : null,
278
+ row.jump ? 'Renewal jumps' : null, !row.eligible ? '.' + row.ending + ' needs ' + eligibilityNeed(row.ending) : null,
226
279
  row.source, row.checkedAt, row.priceAt ? 'Price checked ' + row.priceAt : null].filter(Boolean).join(' · ');
227
280
  }
228
281
 
229
- function render(groups, lines, checkedAt, coverage, watch) {
282
+ function render(groups, lines, checkedAt, coverage, watch, companyType) {
230
283
  const title = watch ? 'Domain watch' : 'Domain results';
231
284
  const [intro, ...body] = lines;
232
285
  const comparison = body.filter(line => /^(?:Cheapest|Best value):/.test(line));
@@ -236,6 +289,8 @@ function render(groups, lines, checkedAt, coverage, watch) {
236
289
  Object.entries(coverage ?? {}).map(([name, count]) => name + ' ' + count + '% answered').join(' · ');
237
290
  const articles = groups.map((group, index) => {
238
291
  const { row } = group;
292
+ const handles = handleLines(group);
293
+ const priority = handlePriority(group, companyType);
239
294
  const rows = group.records.map(record => {
240
295
  const [now, renew] = amountsFor(record);
241
296
  return '<tr><th scope="row"><code>' + escape(record.domain) + '</code><small>' + escape(rowNote(record))
@@ -243,11 +298,14 @@ function render(groups, lines, checkedAt, coverage, watch) {
243
298
  + '</small></th><td>' + escape(now) + '</td><td>' + escape(renew) + '</td></tr>';
244
299
  });
245
300
  return '<article id="name-' + index + '"><h2>' + escape(row.name) + '</h2>'
246
- + (row.verdict ? paragraph(plain(row.verdict) + '. ' + evidenceText(row.reason).split(' · ')[0]) + paragraph(signals(group)) : '')
301
+ + (row.verdict ? paragraph(plain(row.verdict) + '. ' + evidenceText(row.reason).split(' · ')[0]) + paragraph(nameSnapshot(group)) : '')
247
302
  + '<table><caption>Endings · USD before tax</caption><thead><tr><th scope="col">Ending</th><th scope="col">Today</th><th scope="col">Renewal</th></tr></thead><tbody>'
248
303
  + rows.join('') + '</tbody></table>'
249
304
  + (row.verdict ? '<details><summary>Trademark, app and web evidence</summary><ul>'
250
305
  + details(group).map(([label, url]) => '<li>' + (url ? anchor(label, url) : escape(label)) + '</li>').join('') + '</ul></details>' : '')
306
+ + (handles.length ? '<details><summary>Handles</summary>' + (priority ? paragraph(priority) : '') + '<ul>'
307
+ + handles.map(([label, url]) => '<li>' + (url ? anchor(label, url) : escape(label)) + '</li>').join('') + '</ul></details>'
308
+ : row.verdict ? '<p><small>Handles: checked for the top three names.</small></p>' : '')
251
309
  + '</article>';
252
310
  });
253
311
  const html = '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">'
@@ -261,11 +319,13 @@ function render(groups, lines, checkedAt, coverage, watch) {
261
319
  + articles.join('') + '<footer>' + (sources ? paragraph(sources) : '') + '<p>You hold the leash.</p></footer></main></body></html>\n';
262
320
  const md = ['# ' + title, '', 'Domain Hound · ' + checkedAt, '', ...lines, '',
263
321
  ...groups.flatMap(group => ['## ' + markdown(group.row.name), '',
264
- ...(group.row.verdict ? [markdown(group.row.verdict + '. ' + group.row.reason), markdown(signals(group)), ''] : []),
322
+ ...(group.row.verdict ? [markdown(group.row.verdict + '. ' + group.row.reason), markdown(nameSnapshot(group)), ''] : []),
265
323
  '| Ending | Today (USD) | Renewal (USD) | Evidence | Shop |', '| --- | --- | --- | --- | --- |',
266
324
  ...group.records.map(record => '| ' + [record.domain, ...amountsFor(record), markdown(rowNote(record)),
267
325
  record.checkout ? '[' + markdown(record.shop ?? 'Check at shop') + '](' + record.checkout + ')' : ''].join(' | ') + ' |'),
268
- '', ...(group.row.verdict ? details(group).map(([label, url]) => '- ' + (url ? '[' + markdown(label) + '](' + url + ')' : markdown(label))) : []), '']),
326
+ '', ...(group.row.verdict ? details(group).map(([label, url]) => '- ' + (url ? '[' + markdown(label) + '](' + url + ')' : markdown(label))) : []),
327
+ ...(handleLines(group).length ? ['', '### Handles', '', ...(handlePriority(group, companyType) ? [markdown(handlePriority(group, companyType)), ''] : []), ...handleLines(group).map(([label, url]) =>
328
+ '- ' + (url ? '[' + markdown(label) + '](' + url + ')' : markdown(label)))] : []), '']),
269
329
  ...(sources ? [markdown(sources), ''] : []), 'You hold the leash.', ''].join('\n');
270
330
  return { html, md };
271
331
  }
@@ -338,8 +398,12 @@ export function resultPages({ env = process.env,
338
398
  return (data, args, { triage = false, watch = false } = {}) => {
339
399
  const work = writes.then(async () => {
340
400
  const at = data.checkedAt ?? new Date().toISOString();
341
- const groups = watch ? [] : resultGroups(data);
342
- const lines = watch ? data.say.split('\n') : summary(groups, args, triage);
401
+ const groups = watch ? [] : resultGroups(data, args.eligible);
402
+ const lines = watch ? data.say.split('\n') : data.pending ? [
403
+ 'Still checking trademark, app and web sources. Registry answers so far are on the page.',
404
+ 'Repeat the same lookup to collect the rest.',
405
+ ...(args.purchase ? ['Domain Hound cannot buy or complete checkout.'] : []),
406
+ ] : summary(groups, args, triage);
343
407
  const title = watch ? data.domain : groups[0]?.row.name;
344
408
  await mkdir(directory, { recursive: true, mode: 0o700 });
345
409
  // If a caller points us at a shared directory, don't expose the searched name in its listing.
@@ -347,7 +411,7 @@ export function resultPages({ env = process.env,
347
411
  const slug = (privateListing && normalizeName(String(title).split('.')[0]) || 'results').slice(0, 30);
348
412
  const base = new Date().toISOString().replaceAll(/[:.]/g, '-') + '-' + slug + '-' + randomUUID().slice(0, 8);
349
413
  const filename = resolve(directory, base + '.html');
350
- const page = render(groups, lines, at, data.sources, watch ? data : null);
414
+ const page = render(groups, lines, at, data.sources, watch ? data : null, args.companyType);
351
415
  const markdownPath = resolve(directory, base + '.md');
352
416
  await writePrivate(markdownPath, page.md);
353
417
  try {
package/server.json CHANGED
@@ -2,14 +2,14 @@
2
2
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
3
  "name": "dev.domainhound/domain-hound",
4
4
  "title": "Domain Hound",
5
- "description": "Check domain availability and prices, and screen product names, from your AI assistant.",
5
+ "description": "Find a startup name and domain you can buy: availability, prices, app names, trademarks, handles.",
6
6
  "websiteUrl": "https://domainhound.dev",
7
- "version": "0.1.4",
7
+ "version": "0.1.5",
8
8
  "packages": [
9
9
  {
10
10
  "registryType": "npm",
11
11
  "identifier": "domain-hound",
12
- "version": "0.1.4",
12
+ "version": "0.1.5",
13
13
  "transport": {
14
14
  "type": "stdio"
15
15
  }
package/server.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import { geoInstruction, namingRecipe } from './clis/domain-check/naming-method.mjs';
2
- import { asciiDomain, defaultEndings, normalizeName, restrictedEndings, validEligibility } from './clis/domain-check/name-search.mjs';
2
+ import { asciiDomain, defaultEndings, domainEnding, normalizeName, requestEndings, restrictedEndings, supportedEndings, validEligibility } from './clis/domain-check/name-search.mjs';
3
3
  import { spawn } from 'node:child_process';
4
4
  import { readFileSync } from 'node:fs';
5
5
  import { createInterface } from 'node:readline';
6
6
  import { fileURLToPath, pathToFileURL } from 'node:url';
7
+ import { checkSocialHandles, handlePriorities, pendingHandleRows, requestPlatforms } from './clis/domain-check/handles.mjs';
7
8
  import { progressPrefix } from './clis/domain-check/progress.mjs';
8
9
  import { attributed, errorText, progressText } from './display.mjs';
9
10
  import { resultPages } from './results.mjs';
@@ -26,27 +27,39 @@ const versions = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
26
27
  // spaces, punctuation and symbols without needing a Unicode-aware regular expression in the client.
27
28
  const letter = 'A-Za-z0-9\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u1FFF\\u3040-\\uD7FF\\uF900-\\uFDCF';
28
29
  const entryPattern = new RegExp('^[' + letter + '](?:[' + letter + '-]{0,61}[' + letter + '])?'
29
- + '(?:\\.(?:[A-Za-z]{2,63}|[xX][nN]--[A-Za-z0-9](?:[A-Za-z0-9-]{0,57}[A-Za-z0-9])?))?$');
30
+ + '(?:\\.(?:[cC][oO]\\.[uU][kK]|[A-Za-z]{2,63}|[xX][nN]--[A-Za-z0-9](?:[A-Za-z0-9-]{0,57}[A-Za-z0-9])?))?$');
30
31
  const nameSchema = { type: 'string', minLength: 1, maxLength: 127, pattern: entryPattern.source };
31
32
  const endingsSchema = {
32
- type: 'array', minItems: 1, maxItems: 10, uniqueItems: true,
33
- items: { type: 'string', enum: defaultEndings },
34
- description: 'Endings to consider for the recommendation, in preference order. For .com only use ["com"]. The page still shows all ten endings for bare names.',
33
+ type: 'array', minItems: 1, maxItems: supportedEndings.length, uniqueItems: true,
34
+ items: { type: 'string', enum: supportedEndings },
35
+ description: 'Endings to consider for the recommendation, in preference order. For .com only use ["com"]. The page still shows all fourteen default endings for bare names. '
36
+ + 'On request only (add them here when the person asks or names a country): ' + requestEndings.map(ending => '.' + ending).join(', ') + '.',
35
37
  };
38
+ const countryEnding = {
39
+ SH: 'sh', GG: 'gg', SE: 'se', DK: 'dk', DE: 'de', GB: 'co.uk', UK: 'co.uk', EU: 'eu',
40
+ };
41
+ const europeanCountries = new Set('AT BE BG HR CY CZ EE FI FR GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES IS LI NO'.split(' '));
42
+ function regionalEnding(country) {
43
+ const code = country?.toUpperCase();
44
+ return Object.hasOwn(countryEnding, code) ? countryEnding[code] : europeanCountries.has(code) ? 'eu' : null;
45
+ }
46
+ const selectedEndings = args => [...new Set([...(args.endings ?? []), regionalEnding(args.country), ...defaultEndings].filter(Boolean))];
36
47
  const lookupProperties = {
48
+ country: { type: 'string', pattern: '^[A-Za-z]{2}$', description: 'Buyer country code if supplied, such as SE, DK, DE or GB for .co.uk. Do not infer it from language alone.' },
37
49
  ai: { type: 'boolean', description: 'Legacy option. .ai is now included by default.' },
38
50
  endings: endingsSchema,
39
51
  budget: { type: 'number', minimum: 0, maximum: 1000000,
40
52
  description: 'Maximum upfront price in USD when the person gave a cap. Carry it from the registry screen into triage.' },
41
53
  eligible: { type: 'array', uniqueItems: true, items: { type: 'string', enum: restrictedEndings },
42
- description: 'Restricted endings the buyer qualifies to register. Pass ["no"] only when the buyer qualifies for .no.' },
54
+ description: 'Restricted endings the buyer qualifies to register. Pass no or eu only when the buyer qualifies for that ending.' },
43
55
  };
44
56
  const relay = 'Relay `say` as written. You may add advice, but no domain, price or verdict that is not in it. Keep advice consistent with the tool verdict. The complete local results page has all checked endings.';
45
57
  const checkTool = {
46
58
  name: 'check_domains',
47
59
  description: relay + ' '
48
60
  + 'For any request to buy or register, pass purchase: true and explicitly say “Domain Hound cannot buy or complete checkout,” even when the domain is taken. '
49
- + 'Input: query for one name or exact domain ({"query":"lanternbay.me"}), or names for 1 to 20 names in one call ({"names":["lanternbay","lanternbay.me"]}). A bare name checks ten endings, including .ai. '
61
+ + 'Use to check domain availability and prices, whether a domain is taken, or to find a domain for a startup name. '
62
+ + 'Input: query for one name or exact domain ({"query":"lanternbay.me"}), or names for 1 to 20 names in one call ({"names":["lanternbay","lanternbay.me"]}). A bare name checks fourteen endings, including .ai, .net and .org. '
50
63
  + 'For a bare name, put any ending preference in endings. Use exact lookup for a full domain. '
51
64
  + 'For a batch, make one call and report check-at-shop endings as returned. Recheck only when the person asks. '
52
65
  + 'Set confirm true only when the person asks for a live shop check (slower). '
@@ -75,7 +88,7 @@ const legacyTool = { ...checkTool, name: 'broker_find',
75
88
  const triageTool = {
76
89
  name: 'triage_names',
77
90
  description: relay + ' '
78
- + 'Use to screen 1 to 20 product names, or once with a bare name when asked whether an existing name is safe: {"names":["Quiet Otter","Hush Room"],"about":"book quiet meeting rooms"}. Checks same-name rivals and their traction, live US marks, iOS and Android apps, handles and every domain ending, including .ai. '
91
+ + 'Use to screen 1 to 20 product names, or once with a bare name when asked whether an existing name is safe or whether an app name or handle is taken: {"names":["Quiet Otter","Hush Room"],"about":"book quiet meeting rooms"}. Checks every domain ending, including .ai, for all names; same-name rivals and their traction, live US marks, iOS and Android apps, and public company results for the first five names. Social handles for the top three run after the result and can be collected with the same call. Put the strongest names first. '
79
92
  + 'Verdicts weigh each same-name rival by its traction: a strong rival (David vs Goliath) or a same-business rival with traction means Avoid; small or dormant same-name uses are notes that never lower the verdict. '
80
93
  + 'Put the name the person came with first. Fill geo for each name from memory, never from search. '
81
94
  + 'The tool checks Google itself. If you check a gap using built-in search, use it for context and keep the evidence-backed results unchanged. Let the person choose.',
@@ -86,6 +99,10 @@ const triageTool = {
86
99
  names: { type: 'array', minItems: 1, maxItems: 20, items: { type: 'string', minLength: 1, maxLength: 100 },
87
100
  description: '1 to 20 bare names without endings, e.g. ["Quiet Otter","Hush Room"].' },
88
101
  purchase: { type: 'boolean', description: 'True when the person asks to buy or register a domain.' },
102
+ companyType: { type: 'string', enum: Object.keys(handlePriorities),
103
+ description: 'Use developer, consumer, b2b or media when it fits, to highlight the handles that matter.' },
104
+ additionalHandles: { type: 'array', uniqueItems: true, items: { type: 'string', enum: requestPlatforms.map(platform => platform.id) },
105
+ description: 'Extra check links only when requested. Snapchat, Reddit, Twitch, Threads, Pinterest or Discord.' },
89
106
  category: { type: 'string', minLength: 1, maxLength: 100, description: 'Category for relevant trademark classes and competitors. Use travel, software, finance, retail, health, education, food or media.' },
90
107
  about: { type: 'string', minLength: 1, maxLength: 160, description: 'A short description of what your product does, to identify overlapping sites and apps.' },
91
108
  geo: { type: 'object', maxProperties: 20,
@@ -99,7 +116,7 @@ const triageTool = {
99
116
 
100
117
  const namingTool = {
101
118
  name: 'naming_method',
102
- description: 'Get the Domain Hound naming recipe for new names. For an existing name, use triage_names. The recipe and preliminary check are intermediate. For the final triage result, relay say as written.',
119
+ description: 'Use to find a startup or product name: get the Domain Hound naming recipe for new names. For an existing name, use triage_names. The recipe and preliminary check are intermediate. For the final triage result, relay say as written.',
103
120
  inputSchema: { type: 'object', properties: {
104
121
  about: { type: 'string', minLength: 1, maxLength: 512, description: 'An optional one-sentence product description.' },
105
122
  }, additionalProperties: false },
@@ -164,13 +181,18 @@ function lookupFlags(args) {
164
181
  }
165
182
  // The headless browser runs only on this explicit request.
166
183
  if (args.confirm === true) flags.push('--confirm');
184
+ if (Object.hasOwn(args, 'country') && (typeof args.country !== 'string' || !/^[A-Za-z]{2}$/.test(args.country))) {
185
+ throw new Error('Use a two-letter country code.');
186
+ }
167
187
  if (Object.hasOwn(args, 'endings')) {
168
188
  const endings = args.endings;
169
- if (!Array.isArray(endings) || endings.length < 1 || endings.length > 10 ||
189
+ if (!Array.isArray(endings) || endings.length < 1 || endings.length > supportedEndings.length ||
170
190
  new Set(endings).size !== endings.length || endings.some(ending => !endingsSchema.items.enum.includes(ending))) {
171
191
  throw new Error('Choose supported domain endings.');
172
192
  }
173
193
  }
194
+ const extra = selectedEndings(args).filter(ending => !defaultEndings.includes(ending));
195
+ if (extra.length) flags.push('--endings', [...defaultEndings, ...extra].join(','));
174
196
  return flags;
175
197
  }
176
198
 
@@ -195,13 +217,13 @@ function cliArguments(args) {
195
217
  // The rows a progress answer lists, in input order: a bare name with every requested ending, an exact domain as itself.
196
218
  function checkRows(args) {
197
219
  const names = (Object.hasOwn(args, 'query') ? [queryValue(args.query)] : batchNames(args.names)).map(dnsForm);
198
- const endings = [...new Set([...(args.endings ?? []), ...defaultEndings])];
220
+ const endings = selectedEndings(args);
199
221
  return [...new Set(names)].map(name => name.includes('.')
200
222
  ? { name, domains: [name] } : { name, domains: endings.map(ending => name + '.' + ending) });
201
223
  }
202
224
 
203
225
  function triageRows(args) {
204
- const endings = [...new Set([...(args.endings ?? []), ...defaultEndings])];
226
+ const endings = selectedEndings(args);
205
227
  const seen = new Set();
206
228
  return args.names.flatMap(name => {
207
229
  const label = normalizeName(name);
@@ -235,6 +257,13 @@ function triageArguments(args) {
235
257
  throw new Error('names[' + bad + '] is not valid. Supply 1 to 20 bare names of up to 100 characters, without commas or domain endings.');
236
258
  }
237
259
  const flags = lookupFlags(args);
260
+ const { companyType, additionalHandles } = args;
261
+ if (companyType !== undefined && !Object.hasOwn(handlePriorities, companyType)) throw new Error('Choose a supported company type.');
262
+ if (additionalHandles !== undefined && (!Array.isArray(additionalHandles) ||
263
+ new Set(additionalHandles).size !== additionalHandles.length ||
264
+ additionalHandles.some(id => !requestPlatforms.some(platform => platform.id === id)))) {
265
+ throw new Error('Choose supported extra handle platforms.');
266
+ }
238
267
  if (Object.hasOwn(args, 'category')) {
239
268
  if (typeof args.category !== 'string' || !args.category.trim() || args.category.length > 100) {
240
269
  throw new Error('Use up to 100 characters for the product category.');
@@ -289,7 +318,7 @@ function startLookup(args, cwd, maxMs) {
289
318
  const lookup = { started: performance.now(), progress: { answers: new Map(), stage: null }, finished: false,
290
319
  collect: false, outcome: null };
291
320
  const child = spawn(process.execPath, ['index.mjs', ...args], {
292
- cwd, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, DOMAIN_HOUND_PROGRESS: '1' },
321
+ cwd, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, DOMAIN_HOUND_PROGRESS: '1', DOMAIN_HOUND_DEFER_HANDLES: args[0] === '--triage' ? '1' : '' },
293
322
  });
294
323
  lookup.child = child;
295
324
  const chunks = [];
@@ -335,14 +364,27 @@ async function within(lookup, budget) {
335
364
  return finished;
336
365
  }
337
366
 
367
+ function pendingTriage(progress, rows) {
368
+ return {
369
+ pending: true,
370
+ checkedAt: new Date().toISOString(),
371
+ names: rows.map(({ name, domains }) => {
372
+ const endings = state => domains.filter(domain => progress.answers.get(domain) === state).map(domainEnding);
373
+ return { name, taken: endings('taken'), premium: endings('premium'), reserved: endings('reserved'),
374
+ free: endings('probably-free').map(d => ({ d })), shop_check: endings('check-at-shop') };
375
+ }),
376
+ };
377
+ }
378
+
338
379
  export async function serve({
339
380
  input = process.stdin, output = process.stdout, cwd = capabilityDir, timeout = timeoutMs, maxLookup = maxLookupMs,
340
- pages = resultPages(), watch = watchDomain,
381
+ pages = resultPages(), watch = watchDomain, socialLookup = checkSocialHandles,
341
382
  } = {}) {
342
383
  const send = response => output.write(JSON.stringify({ jsonrpc: '2.0', ...response }) + '\n');
343
384
  const error = (id, code, message) => send({ id, error: { code, message } });
344
385
  const pending = new Set();
345
386
  const lookups = new Map();
387
+ const background = new Set();
346
388
 
347
389
  // Join the running or finished lookup for the same input, or start one. Answer within the budget with the
348
390
  // result, or with the progress so far while the lookup keeps running for a repeated call to collect.
@@ -373,7 +415,7 @@ export async function serve({
373
415
  if (!await within(lookup, timeout - (performance.now() - started))) {
374
416
  lookup.collect = true;
375
417
  try {
376
- return toolResult(renderProgress(lookup.progress, {
418
+ return toolResult(await renderProgress(lookup.progress, {
377
419
  rows, elapsedMs: performance.now() - lookup.started, budgetMs: timeout }));
378
420
  } catch {
379
421
  return errorResult('Domain Hound could not format the progress.');
@@ -384,7 +426,7 @@ export async function serve({
384
426
  return errorResult(lookup.outcome.error);
385
427
  }
386
428
  try {
387
- return toolResult(JSON.stringify(await render(lookup.outcome.data)));
429
+ return toolResult(JSON.stringify(await render(lookup.outcome.data, lookup)));
388
430
  } catch {
389
431
  return errorResult('Domain Hound could not format the result.');
390
432
  }
@@ -446,8 +488,56 @@ export async function serve({
446
488
  }
447
489
  const purchase = isObject(args) && args.purchase === true;
448
490
  if (name === triageTool.name) {
449
- return reply(await runLookup(args, triageArguments, triageRows, data => pages(data, args, { triage: true }),
450
- (progress, timing) => progressText(progress, { ...timing, triage: true, purchase })));
491
+ let collect;
492
+ const result = await runLookup(args, triageArguments, triageRows, (data, lookup) => {
493
+ const { handleTargets, ...evidence } = data;
494
+ if (!handleTargets?.length) return pages(evidence, args, { triage: true });
495
+ const extraPlatforms = args.additionalHandles ?? [];
496
+ const key = JSON.stringify(extraPlatforms.slice().sort());
497
+ lookup.handleChecks ??= new Map();
498
+ let check = lookup.handleChecks.get(key);
499
+ if (!check) {
500
+ check = { rows: null, started: false };
501
+ lookup.handleChecks.set(key, check);
502
+ }
503
+ const targets = new Map(handleTargets.map(({ name, index }) => [index, name]));
504
+ const entries = evidence.names.flatMap((row, index) => {
505
+ const target = targets.get(index);
506
+ if (!target) return [];
507
+ const rows = check.rows?.get(target) ?? pendingHandleRows(target, extraPlatforms);
508
+ return [[row.name, rows]];
509
+ });
510
+ const handleRows = new Map(entries);
511
+ evidence.receiptDetails = evidence.receiptDetails.map((detail, index) => ({
512
+ ...detail, handles: handleRows.get(evidence.names[index].name),
513
+ }));
514
+ evidence.handles = Object.fromEntries(entries.map(([name, rows]) => [name, {
515
+ taken: rows.filter(row => row.state === 'taken').map(row => row.platform),
516
+ not_found: rows.filter(row => row.state === 'not-found').map(row => row.platform),
517
+ check: rows.filter(row => row.state === 'check').map(row => row.platform),
518
+ }]));
519
+ if (!check.rows) evidence.handlesPending = true;
520
+ collect = () => {
521
+ if (check.started) return;
522
+ check.started = true;
523
+ const rows = [...new Set(targets.values())].map(name => ({ name, variants: true }));
524
+ const task = socialLookup(rows, { extraPlatforms, freshRun: true })
525
+ .then(answers => { check.rows = answers; }, () => {
526
+ check.rows = new Map(rows.map(({ name }) => [name,
527
+ pendingHandleRows(name, extraPlatforms).map(row => ({ ...row, why: 'no clear answer in time' }))]));
528
+ }).finally(() => background.delete(task));
529
+ background.add(task);
530
+ };
531
+ return pages(evidence, args, { triage: true });
532
+ }, async (progress, timing) => {
533
+ const summary = progressText(progress, { ...timing, triage: true, purchase });
534
+ if (!progress.answers.size) return summary;
535
+ const { resultPage } = await pages(pendingTriage(progress, timing.rows), args, { triage: true });
536
+ return JSON.stringify({ ...JSON.parse(summary), resultPage });
537
+ });
538
+ reply(result);
539
+ if (!result.isError) collect?.();
540
+ return;
451
541
  }
452
542
  if (name !== checkTool.name && name !== legacyTool.name) return error(id, -32602, 'Unknown tool');
453
543
  // An exact lookup includes the purchase line while its registration status is unsettled.
@@ -462,6 +552,7 @@ export async function serve({
462
552
  pending.add(response);
463
553
  }
464
554
  await Promise.all(pending);
555
+ await Promise.all(background);
465
556
  // The client has gone, so nobody can collect a lookup that is still running.
466
557
  for (const lookup of lookups.values()) if (!lookup.finished) lookup.child.kill('SIGKILL');
467
558
  await Promise.all([...lookups.values()].map(lookup => lookup.done));