domain-hound 0.1.7 → 0.1.9

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 (45) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/.claude-plugin/plugin.json +2 -2
  4. package/README.md +89 -24
  5. package/clis/domain-check/company-search.mjs +1 -0
  6. package/clis/domain-check/dossier.mjs +16 -13
  7. package/clis/domain-check/google-play.mjs +11 -48
  8. package/clis/domain-check/google-search.mjs +3 -2
  9. package/clis/domain-check/handles.mjs +235 -106
  10. package/clis/domain-check/index.mjs +49 -28
  11. package/clis/domain-check/name-score.mjs +348 -0
  12. package/clis/domain-check/name-search.mjs +70 -18
  13. package/clis/domain-check/naming-method.mjs +37 -8
  14. package/clis/domain-check/price-catalog.mjs +33 -14
  15. package/clis/domain-check/price-snapshot.json +91 -0
  16. package/clis/domain-check/prices.mjs +5 -0
  17. package/clis/domain-check/public-name-checks.mjs +275 -0
  18. package/clis/domain-check/score-log.mjs +54 -0
  19. package/clis/domain-check/triage-sources.mjs +4 -1
  20. package/clis/domain-check/triage.mjs +131 -83
  21. package/clis/domain-check/youtube-handle.mjs +18 -0
  22. package/clis/portfolio/checks.mjs +456 -0
  23. package/clis/portfolio/discover.mjs +175 -0
  24. package/clis/portfolio/move.mjs +297 -0
  25. package/clis/portfolio/page.mjs +140 -0
  26. package/clis/portfolio/portfolio.mjs +212 -0
  27. package/clis/portfolio/store.mjs +62 -0
  28. package/clis/portfolio/transfer-prices.mjs +41 -0
  29. package/clis/spaceship/client.mjs +35 -19
  30. package/clis/spaceship/tools.mjs +105 -17
  31. package/clis/spaceship/transfer.mjs +332 -0
  32. package/display.mjs +62 -61
  33. package/dossier.mjs +8 -5
  34. package/hosted-results.mjs +157 -0
  35. package/hosted.mjs +164 -0
  36. package/package.json +21 -3
  37. package/plugin.json +8 -8
  38. package/results-style.mjs +3 -0
  39. package/results.mjs +149 -94
  40. package/server.json +4 -4
  41. package/server.mjs +216 -28
  42. package/share.mjs +18 -6
  43. package/site/r/share-format.mjs +23 -8
  44. package/skills/naming/SKILL.md +76 -0
  45. package/watch.mjs +3 -3
@@ -1,5 +1,6 @@
1
- import { canRecommend, defaultEndings, eligibilityNotes, endingTier, nameCandidates, normalizeName, searchCandidates, searchKey,
2
- validEligibility, validEndings } from './name-search.mjs';
1
+ import { canRecommend, comparePicks, defaultEndings, eligibilityNotes, nameCandidates, pickName, normalizeName, searchCandidates,
2
+ searchKey, validEligibility, validEndings } from './name-search.mjs';
3
+ import { compactScore, compareScores, scoreEligible, scoreHandles, scoreName, validCandidate } from './name-score.mjs';
3
4
  import { shopSearchUrl } from './prices.mjs';
4
5
  import { checkHandles, compactText, handleSearches, letters, markOrder, searchApps, searchEntities, searchMarks, trademarkSearches }
5
6
  from './triage-sources.mjs';
@@ -10,7 +11,7 @@ import { mapLimit } from './cache.mjs';
10
11
  import { setTimeout as delay } from 'node:timers/promises';
11
12
  import { checkSocialHandles } from './handles.mjs';
12
13
  import { checkDomainSite } from './com-site.mjs';
13
- import { playSearchLink, searchAndroidApps } from './google-play.mjs';
14
+ import { playSearchLink } from './google-play.mjs';
14
15
  import { googleSearchLink, lowerVerdict, nameCheckLines, searchGoogle } from './google-search.mjs';
15
16
  import { autocompleteWords, collectRivals, createTraction, evidenceLifetime, judgeRivals, parseGeo, siteDomain, startEvidence,
16
17
  tractionNotes, tractionSummary, tractionVerdict } from './traction.mjs';
@@ -73,6 +74,13 @@ function describedBusiness(name, text, about, category) {
73
74
  (pattern.test(description) || (!about && stem.test(name))) && pattern.test(descriptor));
74
75
  }
75
76
 
77
+ // The caller's evidence for one name (triage_names candidates), matched by DNS label like geo. Invalid entries count as missing.
78
+ function candidateFor(candidates, name) {
79
+ if (!candidates || typeof candidates !== 'object') return {};
80
+ const entry = Object.entries(candidates).find(([key]) => normalizeName(key) === name)?.[1];
81
+ return validCandidate(entry) ? entry : {};
82
+ }
83
+
76
84
  export function memorability(name, input) {
77
85
  const parts = input.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase()
78
86
  .normalize('NFKD').replace(/\p{M}/gu, '').match(/[a-z]+/g) ?? [];
@@ -88,7 +96,7 @@ export function memorability(name, input) {
88
96
  }
89
97
 
90
98
  function siteEvidence(row, site) {
91
- if (row?.status === 'probably-free') return 'Registry free';
99
+ if (row?.status === 'probably-free') return 'Available at the registry';
92
100
  if (row?.status !== 'taken') return 'Registry unresolved';
93
101
  if (site?.state === 'live') return site.title ? 'Live: ' + compactText(site.title, 75) : 'Live site';
94
102
  if (site?.state === 'for-sale' || row.forSale) return 'Taken, possible resale';
@@ -138,10 +146,9 @@ function sameNameEvidence({ name, live, norway, us, entities, entity, github, ha
138
146
  };
139
147
  }
140
148
 
141
- function appStatus(ios, android) {
149
+ function appStatus(ios) {
142
150
  const taken = (store, matches) => 'taken on ' + store + (matches[0].seller ? ' (' + matches[0].seller + ')' : '');
143
- return 'App name: ' + (ios ? ios.length ? taken('iOS', ios) : 'free on iOS' : 'iOS not checked') + ', '
144
- + (android ? android.length ? taken('Android', android) : 'free on Android' : 'Android not checked');
151
+ return 'App name: ' + (ios ? ios.length ? taken('iOS', ios) : 'free on iOS' : 'iOS not checked');
145
152
  }
146
153
 
147
154
  // US marks read as before; EU and Norwegian marks name their office and status first.
@@ -171,12 +178,12 @@ function verdict({ mark, otherMark, silent, waiting = [], ...evidence }) {
171
178
  return [decision, [reason, trademark !== reason && trademark, trademarkReason(otherMark), missing].filter(Boolean).join(' · ')];
172
179
  }
173
180
 
174
- function silentSources({ marks, offices, apps, android, entities, norway, edgar, github, handles }) {
181
+ function silentSources({ marks, offices, apps, entities, norway, edgar, github, handles }) {
175
182
  return Object.entries({
176
183
  USPTO: marks,
177
184
  ...Object.fromEntries(offices.filter(result => result.state !== 'off')
178
185
  .map(result => [officeNames[result.office], officeAnswered(result) ? true : null])),
179
- 'App Store': apps, 'Google Play': android, Wikidata: entities, Brønnøysund: norway,
186
+ 'App Store': apps, Wikidata: entities, Brønnøysund: norway,
180
187
  EDGAR: edgar, GitHub: github.status === 'check' ? null : github.status,
181
188
  npm: handles.npm === 'check' ? null : handles.npm,
182
189
  }).filter(([, value]) => value == null).map(([source]) => source);
@@ -200,13 +207,19 @@ function explainedGoogle(name, raw, judged, entities) {
200
207
  && (words === 0 || judged.rivals.some(row => row.level !== 'unknown' && row.rival.autocomplete === words && words > 0));
201
208
  }
202
209
 
210
+ function googleRival(google, explained, subjectKnown) {
211
+ if (explained || !google?.result || google.result === 'open') return [];
212
+ const owned = google.result.startsWith('owned by');
213
+ return [{ level: 'some', sameSubject: owned && google.sameBusiness ? true : owned && !subjectKnown ? null : false }];
214
+ }
215
+
203
216
  // The applet's fast domain lookup stays independent of the slower name checks.
204
217
  export async function namePresence(input, options = {}) {
205
218
  const name = normalizeName(input);
206
219
  if (!name) return { error: 'Enter one name without a domain ending.' };
207
220
  const started = performance.now();
208
221
  const timeLeft = () => 8500 - (performance.now() - started);
209
- const sources = { ...options, signal: AbortSignal.timeout(8500), playBudgetMs: 8000, timeLeft, cacheLifetime: evidenceLifetime };
222
+ const sources = { ...options, signal: AbortSignal.timeout(8500), timeLeft, cacheLifetime: evidenceLifetime };
210
223
  const traction = createTraction({ ...sources, refreshTranco: options.refreshTranco === true });
211
224
  const entityCheck = searchEntities(name, input, sources);
212
225
  const siteChecks = mapLimit(coreWebsiteEndings, 3, async ending => {
@@ -215,19 +228,17 @@ export async function namePresence(input, options = {}) {
215
228
  if (site?.state === 'live') traction.evidence(domain);
216
229
  return [ending, site];
217
230
  });
218
- const [ios, android, google, entities, website] = await Promise.all([
231
+ const [ios, google, entities, website] = await Promise.all([
219
232
  searchApps(name, input, sources),
220
- searchAndroidApps(new Map([[name, input]]), sources),
221
233
  searchGoogle(name, input, { ...sources, entities: entityCheck }),
222
234
  entityCheck, siteChecks,
223
235
  ]);
224
236
  // The applet has no agent: Wikipedia/Wikidata presence stands in for GEO and is labelled so.
225
- const apps = [...(ios ?? []).map(row => ({ ...row, store: 'iOS' })),
226
- ...(android.get(name) ?? []).map(row => ({ ...row, store: 'Android' }))];
237
+ const apps = (ios ?? []).map(row => ({ ...row, store: 'iOS' }));
227
238
  const rivals = collectRivals({ name, input, sites: Object.fromEntries(website), entities, topics: google.raw?.topics, suggestions: google.raw?.suggestions, apps });
228
239
  startEvidence(traction, rivals);
229
240
  const judged = judgeRivals(rivals, await traction.settle(400), { now: (options.now ?? new Date()).getTime(),
230
- answered: { wikidata: entities != null, apps: ios != null && android.has(name) }, entities });
241
+ answered: { wikidata: entities != null, apps: ios != null }, entities });
231
242
  const summary = tractionSummary(judged);
232
243
  const notes = tractionNotes(judged);
233
244
  return { name, ...(summary && { traction: summary }), ...(notes.length && { notes }), checks: nameCheckLines({
@@ -235,15 +246,14 @@ export async function namePresence(input, options = {}) {
235
246
  google: google.google,
236
247
  competition: {
237
248
  AppStore: ios?.map(({ name, seller, ratings }) => ({ name, developer: seller, ratings })),
238
- GooglePlay: android.get(name)?.map(({ name, seller, ratings }) => ({ name, developer: seller, ratings })),
239
249
  },
240
250
  }) };
241
251
  }
242
252
 
243
253
  // Same-name rivals with measured traction follow the traction rules first; evidence whose traction could not be
244
254
  // measured keeps the earlier same-name checks. Trademark and availability guardrails stay in place.
245
- function baseVerdict({ rival, overlap, sameName, activeApp, brand, app, entity, mark, site, best, available, marks, apps, android,
246
- androidAnswered = android, company, premium = [], offices = [] }) {
255
+ function baseVerdict({ rival, overlap, sameName, activeApp, brand, app, entity, mark, site, best, available, marks, apps,
256
+ company, premium = [], offices = [] }) {
247
257
  if (rival?.[0] === 'Avoid') return rival;
248
258
  if (overlap) return ['Avoid', overlap.domain + ' is a live business in the same category'];
249
259
  if (activeApp) return ['Avoid', activeApp.name + ' is an app in the same category with ' + activeApp.ratings + ' ' + activeApp.store + ' ratings'];
@@ -255,16 +265,15 @@ function baseVerdict({ rival, overlap, sameName, activeApp, brand, app, entity,
255
265
  if (mark) return ['Check first', trademarkReason(mark)];
256
266
  if (sameName.level !== 'few') return ['Check first', 'Several public sources show same-name use'];
257
267
  if (app) return ['Check first', 'An exact-name app already exists'];
258
- if (android?.length) return ['Check first', 'An exact-name Android app already exists'];
259
268
  if (site) return ['Check first', site.domain + ' has a live site under this name'];
260
269
  if (entity) return ['Check first', 'An exact-name Wikidata entity already exists'];
261
270
  const answeredOffices = offices.filter(result => result.state !== 'off');
262
- if (!marks || !apps || !androidAnswered || sameName.unchecked?.length || !answeredOffices.every(officeAnswered)) {
271
+ if (!marks || !apps || sameName.unchecked?.length || !answeredOffices.every(officeAnswered)) {
263
272
  return ['Check first', 'A competition source did not answer'];
264
273
  }
265
274
  if (!best) {
266
- return ['Check first', available.length ? 'The free endings require buyer eligibility'
267
- : premium.length ? 'The free endings may be premium, price at shop' : 'No domain was found free at the registry'];
275
+ return ['Check first', available.length ? 'The available endings require buyer eligibility'
276
+ : premium.length ? 'The available endings may be premium, price at shop' : 'The registry did not confirm an available domain'];
268
277
  }
269
278
  const regions = ['US', ...answeredOffices.map(result => ({ EU: 'EU', NO: 'Norwegian' })[result.office])];
270
279
  return ['No conflict found', 'No ' + regions.slice(0, -1).join(', ') + (regions.length > 1 ? ' or ' : '') + regions.at(-1)
@@ -280,7 +289,7 @@ export async function triageNames(inputs, options = {}) {
280
289
  if (options.eligible !== undefined && !validEligibility(options.eligible)) return { error: 'Eligible endings must list supported restricted endings, such as no.' };
281
290
  const endings = options.endings ?? defaultEndings;
282
291
  const preferred = options.preferredEndings ?? [];
283
- const requestedEndings = [...preferred, ...(options.eligible ?? [])];
292
+ const requestedEndings = preferred;
284
293
  const websiteEndings = [...new Set([...endings, ...coreWebsiteEndings])];
285
294
  // Each name has its DNS label (punycode for æøå) for domains, and a Latin key for the rival, app and mark sources.
286
295
  const names = new Map();
@@ -381,18 +390,12 @@ export async function triageNames(inputs, options = {}) {
381
390
  options.onProgress?.({ stage: 'handles' });
382
391
  return evidenceHandles.then(() => checkSocialHandles(order.map(key => ({ name: key, variants: true })), { ...options, signal }));
383
392
  }).catch(() => new Map()));
384
- // Google Play answers per name, so the first pass keeps the names it has.
385
- const playLive = once('playLive', () => new Map());
386
- let playFinished = !answerBy;
387
- const play = once('play', () => searchAndroidApps(new Map(screened.map(([key, input]) => [key, input])),
388
- { ...sources, onResult: (name, apps) => playLive.set(name, apps),
389
- playBudgetMs: Math.min(answerBy ? 20000 : 12000, options.playBudgetMs ?? Infinity, budgetMs) }));
390
393
  const unverifiedHandles = { github: { status: 'check' }, handles: { GitHub: 'check', npm: 'check' } };
391
394
  // Share the optional office lookups between passes and keep them off the first answer's critical path.
392
395
  const officeCheck = office => mapLimit(entries, 4, ([name, input, index]) => isScreened(index)
393
396
  ? byAnswer(once(office + ':' + name, () => checkOffice(office, name, input, sources)),
394
397
  index, officeNames[office], { office, state: 'pending' }) : null);
395
- const [domains, marksByName, appsByName, entitiesByName, handlesByName, norwayByName, androidApps, edgar, googleByName, socialByName,
398
+ const [domains, marksByName, appsByName, entitiesByName, handlesByName, norwayByName, edgar, googleByName, socialByName,
396
399
  euByName, noByName] = await Promise.all([
397
400
  // A cold cache still gets the bundled, dated list prices, so free endings never all read "price at shop".
398
401
  // The second pass also collects the slow website checks.
@@ -405,8 +408,6 @@ export async function triageNames(inputs, options = {}) {
405
408
  ...sources, social: evidenceHandles.then(rows => rows.get(name)).catch(() => null),
406
409
  })), index, 'GitHub repositories', unverifiedHandles) : null)),
407
410
  check(8, searchNorwegianCompanies),
408
- answerBy ? Promise.race([play.then(map => [map, true]), answerBy.then(() => [new Map(playLive), false])])
409
- .then(([map, done]) => { playFinished = done; return map; }) : play,
410
411
  byAnswer(once('edgar', () => retry(() => loadEdgarCompanies(sources), found)), 'all', 'EDGAR'),
411
412
  mapLimit(entries, 5, ([name, input, index]) => isScreened(index) ? byAnswer(once('google:' + name, () => searchGoogle(name, input, {
412
413
  ...sources, timeoutMs: timeLeft(),
@@ -419,10 +420,7 @@ export async function triageNames(inputs, options = {}) {
419
420
  const counts = {};
420
421
  function coverage(source, answered) { counts[source] = (counts[source] ?? 0) + Number(answered); }
421
422
  const geoByName = new Map(Object.entries(options.geo ?? {}).map(([key, value]) => [normalizeName(key), parseGeo(value)]));
422
- const storeAppsByName = domains.groups.map(({ name }, index) => [
423
- ...(appsByName[index] ?? []).map(row => ({ ...row, store: 'iOS', ref: row })),
424
- ...(androidApps.get(keys.get(name)) ?? []).map(row => ({ ...row, store: 'Android', ref: row })),
425
- ]);
423
+ const storeAppsByName = appsByName.map(apps => (apps ?? []).map(row => ({ ...row, store: 'iOS', ref: row })));
426
424
  const rivalsByName = domains.groups.map(({ name, sites }, index) => {
427
425
  if (!isScreened(index)) return [];
428
426
  const raw = googleByName[index].raw ?? {};
@@ -435,17 +433,17 @@ export async function triageNames(inputs, options = {}) {
435
433
  startEvidence(traction, rivals);
436
434
  return rivals;
437
435
  });
438
- if (!playFinished) for (const [key, , index] of screened) if (!androidApps.has(key)) wait(index, 'Google Play');
439
436
  options.onProgress?.({ stage: 'rivals' });
440
437
  // The first pass waits for rival traction only until its answer is due.
441
438
  const evidence = await traction.settle(answerBy ? Math.max(150, timeLeft() - Math.max(0, options.answerAt - performance.now())) : undefined);
442
439
  const rows = domains.groups.map(({ name, results, sites }, index) => {
443
440
  const requested = results.filter(row => endings.includes(row.tld));
444
441
  const available = results.filter(row => row.status === 'probably-free' && endings.includes(row.tld));
442
+ // The person's budget, when given, leaves out rows that cost more upfront (as on the receipt).
445
443
  const recommendable = available.filter(row => canRecommend(row.tld, options.eligible)
446
- && (!preferred.length || preferred.includes(row.tld)));
447
- if (preferred.length) recommendable.sort((a, b) => preferred.indexOf(a.tld) - preferred.indexOf(b.tld));
448
- const [best] = recommendable;
444
+ && (!preferred.length || preferred.includes(row.tld))
445
+ && (options.upfrontCap == null || (row.firstPayment ?? Infinity) <= options.upfrontCap));
446
+ const best = pickName(recommendable, options.eligible, preferred, options.upfrontCap);
449
447
  const social = socialByName.get(keys.get(name)) ?? null;
450
448
  const domainFields = {
451
449
  taken: requested.filter(row => row.status === 'taken').map(row => row.tld),
@@ -466,7 +464,7 @@ export async function triageNames(inputs, options = {}) {
466
464
  // Registry answers and prices only. The verdict never reads "No conflict found" without the checks.
467
465
  return {
468
466
  name: names.get(name), verdict: 'Check first', reason: notScreened,
469
- _free: available, _recommendable: recommendable, _googleExplained: true,
467
+ _free: available, _recommendable: recommendable, _pick: best, _googleExplained: true,
470
468
  google: { result: 'not checked', why: 'not screened', link: googleSearchLink(names.get(name)) },
471
469
  ...domainFields,
472
470
  competition: { US: null, mark: null, AppStore: null, GooglePlay: null, Wikidata: null,
@@ -486,10 +484,9 @@ export async function triageNames(inputs, options = {}) {
486
484
  const brand = entities?.find(row => row.brand);
487
485
  const entity = brand ?? entities?.[0];
488
486
  const key = keys.get(name);
489
- const android = androidApps.get(key);
490
487
  const google = googleByName[index];
491
488
  const judged = judgeRivals(rivalsByName[index], evidence, { now: (options.now ?? new Date()).getTime(),
492
- answered: { wikidata: entities != null, apps: apps != null && android != null },
489
+ answered: { wikidata: entities != null, apps: apps != null },
493
490
  geo: geoByName.get(name), entities });
494
491
  const { explained } = judged;
495
492
  const storeApps = storeAppsByName[index];
@@ -531,7 +528,7 @@ export async function triageNames(inputs, options = {}) {
531
528
  const sitesSilent = sitesWaiting || Object.values(sites).some(site => site?.state === 'unknown');
532
529
  if (answerBy && sitesWaiting) wait(index, 'websites');
533
530
  const pending = waitingFor(index);
534
- const silent = silentSources({ marks, offices, apps, android, entities, norway, edgar, github, handles })
531
+ const silent = silentSources({ marks, offices, apps, entities, norway, edgar, github, handles })
535
532
  .filter(source => (!options.deferHandles || !['GitHub', 'npm'].includes(source)) && !pending.includes(source));
536
533
  if (sitesSilent && !pending.includes('websites')) silent.push('websites');
537
534
  const otherEntity = otherEntities?.find(row => row.brand) ?? otherEntities?.[0];
@@ -539,12 +536,12 @@ export async function triageNames(inputs, options = {}) {
539
536
  rival: tractionVerdict(judged), overlap, sameName: legacy, activeApp,
540
537
  brand: otherEntity?.brand ? otherEntity : undefined, app: apps?.find(row => !explained.has(row)), entity: otherEntity,
541
538
  mark, otherMark, site, silent, waiting: pending, best, available, marks, apps, premium: results.filter(row => row.status === 'premium'),
542
- android: android?.filter(row => !explained.has(row)), androidAnswered: android, company, offices,
539
+ company, offices,
543
540
  });
544
541
  const googleExplained = explainedGoogle(key, googleByName[index].raw, judged, entities);
545
542
  const summary = tractionSummary(judged);
546
543
  const answered = {
547
- USPTO: marks, 'App Store': apps, 'Google Play': android, Google: google.google, Wikidata: entities,
544
+ USPTO: marks, 'App Store': apps, Google: google.google, Wikidata: entities,
548
545
  Brønnøysund: norway, EDGAR: edgar, ...(options.memo && { Websites: sitesSilent ? null : true }),
549
546
  ...Object.fromEntries(offices.filter(result => result.state !== 'off')
550
547
  .map(result => [officeNames[result.office], officeAnswered(result) ? true : null])),
@@ -556,22 +553,61 @@ export async function triageNames(inputs, options = {}) {
556
553
  US: usMark ? trademarkReason(usMark) : marks ? [] : null,
557
554
  mark: usMark?.url ?? null,
558
555
  // EU and NO appear once a key is set: the strongest hit, [] when the office answered in full with none,
559
- // null when it failed or answered in part (check yourself).
556
+ // null when it failed or answered in part.
560
557
  ...Object.fromEntries(offices.filter(result => result.state !== 'off').map(result => {
561
558
  const best = result.marks?.[0];
562
559
  return [result.office, officeAnswered(result) ? (best ? trademarkReason(best) : []) : null];
563
560
  })),
564
561
  ...(officeMarks.length > 0 && { marks: officeMarkEntries(officeMarks.sort(markOrder(key))) }),
565
562
  AppStore: app ? { name: app.name, developer: app.seller, ratings: app.ratings, url: app.url } : apps ? [] : null,
566
- GooglePlay: android?.map(({ name, seller, url, ratings }) => ({ name, developer: seller, url, ratings })).slice(0, 3) ?? null,
563
+ GooglePlay: null,
567
564
  Wikidata: entity ? { name: entity.name, description: entity.description, url: entity.url,
568
565
  ...(entity.brand && { brand: true }) } : entities ? [] : null,
569
566
  sameName,
570
567
  };
568
+ // Name score evidence. A source that did not answer is null, one the follow-up still runs is 'pending'.
569
+ const state = (answer, ...sources) => answer != null ? 'ok' : sources.some(source => pending.includes(source)) ? 'pending' : null;
570
+ const subjectKnown = Boolean(options.about || options.category);
571
+ const euSandbox = (options.env ?? process.env).DOMAIN_HOUND_EUIPO_SANDBOX === '1';
572
+ const eu = euSandbox ? undefined : offices.find(result => result.office === 'EU');
573
+ const rivalSources = ['Google', 'Wikidata', 'App Store', 'websites'];
574
+ const rivalsAnswered = google.google != null && entities != null && apps != null && !sitesSilent
575
+ && judged.rivals.every(row => row.level !== 'unknown');
576
+ const sameSectorCompany = norway?.matches.some(({ match, homepage }) => {
577
+ const domain = siteDomain(homepage);
578
+ return match === 'exact' && domain && judged.rivals.some(({ rival }) =>
579
+ rival.sameBusiness && rival.domains.includes(domain));
580
+ }) ?? false;
581
+ const scoreInput = {
582
+ name: names.get(name), candidate: candidateFor(options.candidates, name),
583
+ // Free endings in scope with a registry answer (never DNS alone) and their payments due in 3 years.
584
+ domains: recommendable.filter(row => row.status === 'probably-free' && ['rdap', 'whois'].includes(row.source))
585
+ .map(row => ({ ending: row.tld, total: row.threeYear ?? null, registry: true })),
586
+ marks: { us: state(marks, 'USPTO') ?? 'unknown',
587
+ eu: eu && officeAnswered(eu) ? 'ok' : eu && pending.includes(officeNames.EU) ? 'pending' : eu?.state === 'off' || !eu ? 'off' : 'unknown',
588
+ list: allMarks.filter(item => !euSandbox || item.office !== 'EU').map(item => ({ tier: item.tier, live: item.live === true ? true : item.live === false ? false : null,
589
+ // Classes unknown: null. Only a verified class overlap can hard-filter.
590
+ sameClass: !item.classes?.length ? null : (item.relevantClasses?.length ?? 0) > 0 })) },
591
+ // Measured rivals count even when another source failed; the state says whether the rival check is complete.
592
+ // A registry homepage links an exact-name company to an independently checked site in the same subject.
593
+ rivals: { state: rivalsAnswered ? 'ok' : rivalSources.some(source => pending.includes(source)) ? 'pending' : 'unknown',
594
+ list: [...judged.rivals.filter(row => row.level !== 'unknown').map(row => ({ level: row.dormant ? 'dormant' : row.level,
595
+ sameSubject: subjectKnown ? Boolean(row.rival.sameBusiness) : null })),
596
+ // Web search evidence no measured rival explains: one brand owning the results, or several uses, counts as
597
+ // a same-name use with some traction (in your subject when the search says so).
598
+ ...googleRival(google.google, explainedGoogle(key, google.raw, judged, entities), subjectKnown)], company: sameSectorCompany },
599
+ apps: { state: state(apps, 'App Store') ?? 'unknown',
600
+ list: storeApps.map(row => ({ sameCategory: subjectKnown
601
+ ? describedBusiness(key, [row.name, row.category, row.description].join(' '), options.about, options.category) : null })) },
602
+ handles: options.deferHandles ? {} : social ? scoreHandles(social)
603
+ : Object.fromEntries(Object.entries(handles).map(([platform, value]) => [platform,
604
+ value === 'taken' ? 'taken' : value === 'not-found' ? 'free' : null])),
605
+ };
571
606
  return {
607
+ _scoreInput: scoreInput,
572
608
  // Small and dormant same-name uses are notes after the reason; they never change the verdict.
573
609
  name: names.get(name), verdict: decision, reason: [reason, ...tractionNotes(judged)].join(' · '),
574
- _free: available, _recommendable: recommendable, _mark: mark, _googleExplained: googleExplained,
610
+ _free: available, _recommendable: recommendable, _pick: best, _mark: mark, _googleExplained: googleExplained,
575
611
  ...(summary && { traction: summary }),
576
612
  google: { ...(google.google ?? { result: 'not checked', why: google.unchecked }), link: googleSearchLink(names.get(name)) },
577
613
  ...domainFields,
@@ -583,8 +619,8 @@ export async function triageNames(inputs, options = {}) {
583
619
  memorable: memorability(key, names.get(name)),
584
620
  presence: Object.fromEntries(Object.entries(handles).map(([service, status]) =>
585
621
  [service, status === 'check' ? null : status])),
586
- sites: Object.fromEntries(seen), appName: appStatus(apps, android),
587
- AndroidSearch: android ? null : playSearchLink(names.get(name)),
622
+ sites: Object.fromEntries(seen), appName: appStatus(apps),
623
+ AndroidSearch: playSearchLink(names.get(name)),
588
624
  },
589
625
  };
590
626
  });
@@ -601,15 +637,30 @@ export async function triageNames(inputs, options = {}) {
601
637
  } else row.reason += ' · Meaning: ' + meaning.note;
602
638
  }
603
639
  row.checks = options.compact ? null
604
- : nameCheckLines(row).map(({ label, text, link }) => label + ': ' + text + ' · ' + link);
640
+ : nameCheckLines(row).map(({ label, text, link, linkLabel }) =>
641
+ (linkLabel ? text + ' · ' + linkLabel : label + ': ' + text) + ' · ' + link);
642
+ // Only the fully screened names get a Name score; bans and hard filters run first, inside scoreName.
643
+ if (row._scoreInput) {
644
+ row._scoreInput.meaning = meaning ? { how: meaning.how } : null;
645
+ row._score = scoreName(row._scoreInput);
646
+ // A legacy Avoid stays a guard. The one exception: the only Avoid is a strong rival with affirmative evidence of a
647
+ // different subject; the score carries that penalty, so the name may still rank.
648
+ const rivals = row._scoreInput.rivals.list;
649
+ if (row._score.value != null && row.verdict === 'Avoid' && /^David vs Goliath: /.test(row.reason) && !row.google?.sameBusiness
650
+ && rivals.some(rival => rival.level === 'strong') && rivals.every(rival => rival.level !== 'strong' || rival.sameSubject === false)) {
651
+ row._score.overridesAvoid = true;
652
+ }
653
+ row.score = compactScore(row._score);
654
+ }
605
655
  }
606
- for (const row of googleCandidates(rows, requestedEndings)) row.google.search = true;
656
+ for (const row of googleCandidates(rows, requestedEndings, options.eligible, options.upfrontCap)) row.google.search = true;
607
657
  const sourcesSummary = Object.fromEntries(Object.entries(counts).map(([source, answered]) =>
608
658
  [source, Math.round(100 * answered / Math.min(names.size, screenLimit))]));
609
- const receiptDetails = options.receipt ? structuredClone(rows.map(({ competition, details, traction, google, reason, meaning, _receiptEndings, _handles, _waiting }) =>
659
+ const receiptDetails = options.receipt ? structuredClone(rows.map(({ competition, details, traction, google, reason, meaning, _receiptEndings, _handles, _waiting,
660
+ _score, _scoreInput }) =>
610
661
  ({ competition, details, traction, google, reason, meaning, endings: _receiptEndings, handles: _handles,
611
- ...(_waiting?.().length && { waiting: _waiting() }) }))) : null;
612
- const result = packTriage(rows, sourcesSummary, options.compact, endings, options.eligible, requestedEndings);
662
+ ...(_waiting?.().length && { waiting: _waiting() }), ...(_score && { score: _score, scoreInput: _scoreInput }) }))) : null;
663
+ const result = packTriage(rows, sourcesSummary, options.compact, endings, options.eligible, requestedEndings, options.upfrontCap);
613
664
  // The first pass of a follow-up run says more checks are coming.
614
665
  if (answerBy && waiting.size) result.followUp = true;
615
666
  if (options.receipt) {
@@ -640,13 +691,13 @@ export function handleOrder(groups, keys, eligible) {
640
691
  function compactHandles(entries) {
641
692
  if (!Array.isArray(entries)) return null;
642
693
  const by = state => entries.filter(entry => entry.state === state).map(entry => entry.platform);
643
- const [taken, notFound, check] = [by('taken'), by('not-found'), by('check')];
694
+ const [taken, notFound, check] = [by('taken'), by('not-found'), by('unknown')];
644
695
  return { ...(taken.length && { taken }), ...(notFound.length && { not_found: notFound }), ...(check.length && { check }) };
645
696
  }
646
697
 
647
698
  // The first three ranked names, filled from the screened names in input order when fewer than three rank.
648
- export function googleCandidates(rows, requested) {
649
- const picked = rankedRows(rows, requested).slice(0, 3);
699
+ export function googleCandidates(rows, requested, eligible, budget) {
700
+ const picked = rankedRows(rows, requested, eligible, budget).slice(0, 3);
650
701
  for (const row of rows) if (picked.length < 3 && !picked.includes(row)) picked.push(row);
651
702
  return picked;
652
703
  }
@@ -674,28 +725,21 @@ export function bestValue(options) {
674
725
  || (row.threeYear === best.threeYear && row.firstPayment < best.firstPayment) ? row : best, undefined);
675
726
  }
676
727
 
677
- // Best value within the most attractive tier that has an in-scope row. When that tier's rows lack a usable three-year
678
- // total, there is no best value yet (it needs a shop quote); a fallback ending never takes over silently.
679
- export function tierBestValue(options, requested = []) {
680
- const tier = Math.min(...options.map(row => endingTier(row.domain, requested)));
681
- return bestValue(options.filter(row => endingTier(row.domain, requested) === tier));
682
- }
683
-
684
- // A name's pick is its first recommendable row (ranked by tier, then upfront payment); a name without one sorts last.
685
- const pickTier = (row, requested) => row._recommendable[0] ? endingTier(row._recommendable[0].domain, requested) : Infinity;
728
+ const pickOption = ({ _pick }) => _pick && { domain: _pick.domain, now: _pick.firstPayment, total: _pick.threeYear };
686
729
 
687
- function rankedRows(rows, requested = []) {
730
+ // Score-ranked picks come first. Unscreened names use the previous verdict and domain order.
731
+ function rankedRows(rows, requested = [], eligible = [], budget) {
688
732
  const order = { 'No conflict found': 0, 'Check first': 1 };
689
- return rows.filter(row => row.verdict !== 'Avoid').sort((a, b) => order[a.verdict] - order[b.verdict]
690
- || pickTier(a, requested) - pickTier(b, requested)
691
- || (a._recommendable[0]?.firstPayment ?? Infinity) - (b._recommendable[0]?.firstPayment ?? Infinity));
733
+ return rows.filter(row => scoreEligible(row)).sort((a, b) => compareScores(a.score, b.score)
734
+ || order[a.verdict] - order[b.verdict]
735
+ || Number(!pickOption(a)) - Number(!pickOption(b))
736
+ || (pickOption(a) && pickOption(b) ? comparePicks(pickOption(a), pickOption(b), { requested, eligible, budget }) : 0));
692
737
  }
693
738
 
694
- function topChoices(rows, requested) {
695
- return rankedRows(rows, requested).slice(0, 3)
696
- .map(({ name, verdict, reason, _recommendable }) => {
697
- const [best] = _recommendable;
698
- const value = tierBestValue(_recommendable, requested);
739
+ function topChoices(rows, requested, eligible, budget) {
740
+ return rankedRows(rows, requested, eligible, budget).slice(0, 3)
741
+ .map(({ name, verdict, reason, _recommendable, _pick: best }) => {
742
+ const value = bestValue(_recommendable);
699
743
  return {
700
744
  name, verdict, reason, domain: best?.domain ?? null, ending: best?.tld ?? null,
701
745
  now: best?.firstPayment ?? null, renew: best?.renewalPayment ?? null, term: best?.minimumYears ?? null,
@@ -706,12 +750,13 @@ function topChoices(rows, requested) {
706
750
  }
707
751
 
708
752
  // Share each ending's standard price once and keep only per-name differences.
709
- function packTriage(rows, sources, compact, endings, eligible, requested = []) {
753
+ function packTriage(rows, sources, compact, endings, eligible, requested = [], budget) {
710
754
  const prices = {};
711
- const top = topChoices(rows, requested);
712
- // Handle states for the top names: taken, not_found (no public profile found) or check (check yourself).
755
+ const top = topChoices(rows, requested, eligible, budget);
756
+ // Compact lists of platforms with taken, missing and unknown handles.
713
757
  const handles = Object.fromEntries(rows.filter(row => row._social).map(row => [row.name, row._social]));
714
- const names = rows.map(({ _free, _recommendable, _mark, _googleExplained, _receiptEndings, _handles, _social, _waiting, ...row }) => {
758
+ const names = rows.map(({ _free, _recommendable, _pick, _mark, _googleExplained, _receiptEndings, _handles, _social, _waiting, _score, _scoreInput,
759
+ ...row }) => {
715
760
  const own = {};
716
761
  for (const option of _free) {
717
762
  const entry = priceEntry(option);
@@ -719,7 +764,7 @@ function packTriage(rows, sources, compact, endings, eligible, requested = []) {
719
764
  if (!prices[option.tld]) prices[option.tld] = entry;
720
765
  else if (JSON.stringify(prices[option.tld]) !== JSON.stringify(entry)) own[option.tld] = entry;
721
766
  }
722
- return { ...row, free: _free.map(option => option.tld), own, bestValue: tierBestValue(_recommendable, requested)?.tld ?? null };
767
+ return { ...row, free: _free.map(option => option.tld), own, bestValue: bestValue(_recommendable)?.tld ?? null };
723
768
  });
724
769
  const result = { top, names, prices, sources, eligibility: eligibilityNotes(endings),
725
770
  ...(Object.keys(handles).length && { handles }),
@@ -732,10 +777,13 @@ function packTriage(rows, sources, compact, endings, eligible, requested = []) {
732
777
  if (size() > limit) for (const row of names) row.buy = null;
733
778
  }
734
779
  for (const trim of [
735
- // Platforms not listed under taken or not_found are "check yourself"; the results page lists them all.
780
+ // The results page retains every platform, including unknowns.
736
781
  () => { for (const value of Object.values(result.handles ?? {})) delete value.check; },
737
782
  // GitHub and npm stand in the handle states and the same-name summary too.
783
+ // The results page and say read the full score from the receipt; the machine field keeps value and band.
784
+ row => { if (row.score) { delete row.score.reasons; delete row.score.notChecked; } },
738
785
  row => { if (row.details) delete row.details.presence; },
786
+ row => { delete row.score; },
739
787
  row => { row.details = null; },
740
788
  row => { row.buy = null; },
741
789
  row => { if (row.traction) delete row.traction.geo; },
@@ -0,0 +1,18 @@
1
+ const channelsEndpoint = 'https://www.googleapis.com/youtube/v3/channels';
2
+
3
+ export const validYouTubeHandle = handle => handle.length >= 3 && handle.length <= 30;
4
+
5
+ export function youtubeHandleUrl(handle) {
6
+ return channelsEndpoint + '?' + new URLSearchParams({ part: 'id', forHandle: '@' + handle });
7
+ }
8
+
9
+ export function classifyYouTubeHandle(status, data) {
10
+ const errors = data?.error?.errors;
11
+ if (status === 404 && Array.isArray(errors) && errors.some(error => error?.reason === 'channelNotFound')) {
12
+ return 'not-found';
13
+ }
14
+ if (status !== 200 || !Array.isArray(data?.items) || data.error) return 'unknown';
15
+ if (data.items.length === 0) return 'not-found';
16
+ const id = data.items[0]?.id;
17
+ return data.items.length === 1 && typeof id === 'string' && /^UC[A-Za-z0-9_-]{22}$/.test(id) ? 'taken' : 'unknown';
18
+ }